FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-sdk/src/cache.js at master · leancloud/javascript-sdk · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
leancloud
/
javascript-sdk
Public
Notifications
You must be signed in to change notification settings
Fork
121
Star
340
Code
Issues
51
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-sdk
/
src
/
cache.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (34 loc) · 905 Bytes
Breadcrumbs
javascript-sdk
/
src
/
cache.js
Copy path
File metadata and controls
38 lines (34 loc) · 905 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const
storage
=
require
(
'./localstorage'
)
;
const
AV
=
require
(
'./av'
)
;
const
removeAsync
=
(
exports
.
removeAsync
=
storage
.
removeItemAsync
.
bind
(
storage
)
)
;
const
getCacheData
=
(
cacheData
,
key
)
=>
{
try
{
cacheData
=
JSON
.
parse
(
cacheData
)
;
}
catch
(
e
)
{
return
null
;
}
if
(
cacheData
)
{
const
expired
=
cacheData
.
expiredAt
&&
cacheData
.
expiredAt
<
Date
.
now
(
)
;
if
(
!
expired
)
{
return
cacheData
.
value
;
}
return
removeAsync
(
key
)
.
then
(
(
)
=>
null
)
;
}
return
null
;
}
;
exports
.
getAsync
=
key
=>
{
key
=
`AV/
${
AV
.
applicationId
}
/
${
key
}
`
;
return
storage
.
getItemAsync
(
key
)
.
then
(
cache
=>
getCacheData
(
cache
,
key
)
)
;
}
;
exports
.
setAsync
=
(
key
,
value
,
ttl
)
=>
{
const
cache
=
{
value
}
;
if
(
typeof
ttl
===
'number'
)
{
cache
.
expiredAt
=
Date
.
now
(
)
+
ttl
;
}
return
storage
.
setItemAsync
(
`AV/
${
AV
.
applicationId
}
/
${
key
}
`
,
JSON
.
stringify
(
cache
)
)
;
}
;
Back
|
FazBrowse Home
|
New Git URL