This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
244 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var CacheWrapper = function(name) { | ||
this._name = name; | ||
this._cache = null; | ||
}; | ||
|
||
CacheWrapper.prototype.open = function() { | ||
if (!this._cache) { | ||
return caches.open(this._name).then(function(cache) { | ||
this._cache = cache; | ||
return cache; | ||
}.bind(this)); | ||
} else { | ||
return Promise.resolve(this._cache); | ||
} | ||
}; | ||
|
||
CacheWrapper.prototype.fetch = function(request) { | ||
return this.open().then(function(cache) { | ||
return cache.match(request); | ||
}); | ||
}; | ||
|
||
CacheWrapper.prototype.put = function(request, response) { | ||
return this.open().then(function(cache) { | ||
cache.put(request, response); | ||
}); | ||
}; | ||
|
||
CacheWrapper.prototype.add = function(requests) { | ||
if (!Array.isArray(requests)) { | ||
requests = [requests]; | ||
} | ||
return this.open().then(function(cache) { | ||
return cache.addAll(requests); | ||
}); | ||
}; | ||
|
||
CacheWrapper.prototype.remove = function(request) { | ||
return this.open().then(function(cache) { | ||
cache.delete(request); | ||
}); | ||
}; | ||
|
||
module.exports = CacheWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var version = 1; | ||
var cachePrefix = 'shed-' + self.scope + '-'; | ||
|
||
module.exports = { | ||
cacheName: cachePrefix + version, | ||
cachePrefix: cachePrefix, | ||
debug: false, | ||
preCacheItems: [], | ||
// A regular expression to apply to HTTP response codes. Codes that match will | ||
// be considered successes, while others will not, and will not be cached. | ||
successResponses: /^0|([123]\d\d)|(40[14567])|410$/, | ||
version: version, | ||
}; |
Oops, something went wrong.