Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libre
Samizdat
Commits
2f047a0b
Commit
2f047a0b
authored
Oct 05, 2020
by
Michał Woźniak
Browse files
WIP #71: cache uses self.log()
parent
deaa0410
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/cache.js
View file @
2f047a0b
...
...
@@ -23,7 +23,7 @@
* getting content from cache
*/
let
getContentFromCache
=
(
url
)
=>
{
console
.
log
(
'
Samizdat:
getting from cache!
'
)
self
.
log
(
config
.
name
,
'
getting from cache!
'
)
return
caches
.
open
(
'
v1
'
)
.
then
((
cache
)
=>
{
return
cache
.
match
(
url
)
...
...
@@ -32,9 +32,13 @@
if
(
typeof
response
===
'
undefined
'
)
{
throw
new
Error
(
'
Resource not found in cache
'
);
}
else
{
response
.
headers
.
forEach
(
function
(
v
,
k
){
console
.
log
(
'
+-- Retrieved cached header:
'
,
k
,
'
::
'
,
v
)
});
self
.
log
(
config
.
name
,
'
retrieved cached headers:
\n
'
,
response
.
headers
.
map
((
v
,
k
)
=>
{
return
`
${
k
}
:
${
v
}
`
}).
join
(
'
\n
+--
'
)
)
// return the response
return
response
}
...
...
@@ -55,11 +59,11 @@
.
then
((
cache
)
=>
{
if
(
typeof
resource
===
'
string
'
)
{
// assume URL
console
.
log
(
"
(COMMIT_UNKNOWN)
caching an URL
"
)
self
.
log
(
config
.
name
,
"
caching an URL
"
)
return
cache
.
add
(
resource
)
}
else
if
(
Array
.
isArray
(
resource
))
{
// assume array of URLs
console
.
log
(
"
(COMMIT_UNKNOWN)
caching an Array of URLs
"
)
self
.
log
(
config
.
name
,
"
caching an Array of URLs
"
)
return
cache
.
addAll
(
resource
)
}
else
{
// assume a Response
...
...
@@ -86,7 +90,7 @@
return
resource
.
blob
()
.
then
((
blob
)
=>
{
console
.
log
(
"
(COMMIT_UNKNOWN)
caching a Response to:
"
+
key
)
self
.
log
(
config
.
name
,
"
caching a Response to:
"
+
key
)
return
cache
.
put
(
key
,
new
Response
(
blob
,
init
...
...
@@ -110,11 +114,11 @@
.
then
((
cache
)
=>
{
if
(
typeof
resource
===
'
string
'
)
{
// assume URL
console
.
log
(
"
(COMMIT_UNKNOWN)
deleting a cached URL
"
)
self
.
log
(
config
.
name
,
"
deleting a cached URL
"
)
return
cache
.
delete
(
resource
)
}
else
if
(
Array
.
isArray
(
resource
))
{
// assume array of URLs
console
.
log
(
"
(COMMIT_UNKNOWN)
deleting an Array of cached URLs
"
)
self
.
log
(
config
.
name
,
"
deleting an Array of cached URLs
"
)
return
Promise
.
all
(
resource
.
map
((
res
)
=>
{
return
cache
.
delete
(
res
)
...
...
@@ -123,7 +127,7 @@
}
else
{
// assume a Response
// which means we have an URL in resource.url
console
.
log
(
"
(COMMIT_UNKNOWN)
removing a Response from cache:
"
+
resource
.
url
)
self
.
log
(
config
.
name
,
"
removing a Response from cache:
"
+
resource
.
url
)
return
cache
.
delete
(
resource
.
url
)
}
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment