Skip to content

Commit 63ac305

Browse files
author
root
committed
first commit
0 parents  commit 63ac305

File tree

8 files changed

+404
-0
lines changed

8 files changed

+404
-0
lines changed

Gruntfile.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* global module:false */
2+
module.exports = function(grunt) {
3+
4+
// Grunt configuration
5+
grunt.initConfig({
6+
pkg: grunt.file.readJSON('package.json'),
7+
meta: {
8+
banner: '/*! Cache API Key/Value Store v<%= pkg.version %>\n * (c) https://github.com/optimalisatie */\n'
9+
},
10+
11+
// closure compiler
12+
"closure-compiler": {
13+
"cache-api-keyval": {
14+
closurePath: 'closure-compiler',
15+
js: 'src/cache-api-keyval.js',
16+
jsOutputFile: 'dist/cache-api-keyval.js',
17+
maxBuffer: 10000,
18+
options: {
19+
compilation_level: 'ADVANCED_OPTIMIZATIONS',
20+
language_in: 'ECMASCRIPT5_STRICT',
21+
externs: ['cache-api-keyval.ext.js'],
22+
define: ['DEBUG=false']
23+
}
24+
}
25+
}
26+
});
27+
28+
// Load Dependencies
29+
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
30+
31+
grunt.registerTask('build', [
32+
'closure-compiler:cache-api-keyval'
33+
]);
34+
grunt.registerTask('default', ['']);
35+
};

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2018 github.com/optimalisatie
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
![Version](https://img.shields.io/github/release/optimalisatie/cache-api-keyval-store.svg)
2+
3+
# Cache API Key/Value store
4+
5+
Fast and efficient key/value store with +50MB storage capacity in [most browsers](https://developer.mozilla.org/en-US/docs/Web/API/Cache#Browser_compatibility), expiration and JSON object data-type.
6+
7+
It’s currently available in Chrome >= 40, Firefox >=39 and Opera >= 27.
8+
9+
Safari and Edge recently introduced support for it.
10+
11+
# Install
12+
13+
```
14+
npm install --save cache-api-keyval
15+
```
16+
17+
# Use
18+
19+
```html
20+
<script src="/cache-api-keyval.js"></script>
21+
<script>
22+
23+
// load database
24+
var db = new CacheApiDB('my-store', { namespace: 'optional' });
25+
26+
if (db.supported) { // Cache API supported by browser
27+
28+
// set JSON object data
29+
db.set('key', { json: 'object' });
30+
31+
// set text data with expiration in 24 hours
32+
db.set('key2', 'string', 86400);
33+
34+
// get data from cache
35+
db.get('key').then(function(json) {
36+
console.log('json cache data', json);
37+
});
38+
39+
// prune expired cache entries
40+
db.prune();
41+
42+
}
43+
</script>
44+
```
45+
46+
## Fallback storage
47+
48+
To enable a fallback storage for browsers that do not support Cache API, you can define a constructor on global variable `CacheApiDBFallback`. The constructor needs to provide 4 methods: `set`, `get`, `del` and `prune`.
49+
50+
```js
51+
window.CacheApiDBFallback = function(store, options) {
52+
53+
this.get = function(key) { /* return key from store */ }
54+
this.set = function(key,data,expire) { /* set key in store */ }
55+
this.det = function(key) { /* delete key from store */ }
56+
this.prune = function() { /* cleanup database */ }
57+
};
58+
```

cache-api-keyval.ext.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Closure Compiler externs
2+
// @link https://developers.google.com/closure/compiler/
3+
4+
window.CacheApiDB = global.CacheApiDB = this.CacheApiDB = self.CacheApiDB = function(store, options) {
5+
6+
options.namespace = '';
7+
8+
return {
9+
supported: false,
10+
get: function() {},
11+
set: function() {},
12+
del: function() {},
13+
prune: function() {}
14+
}
15+
}
16+
17+
var cache_headers = {
18+
"x-date": '',
19+
"x-expire": '',
20+
"Content-Type": ''
21+
};

dist/cache-api-keyval.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
WARNING - unknown @define variable DEBUG
2+
3+
cache-api-keyval.ext.js:4: WARNING - name global is not defined in the externs.
4+
window.CacheApiDB = global.CacheApiDB = this.CacheApiDB = self.CacheApiDB = function(store, options) {
5+
^
6+
7+
0 error(s), 2 warning(s)

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "cache-api-keyval",
3+
"version": "1.0.1",
4+
"description": "Cache API key/value store with expiration and JSON object data-type storage.",
5+
"author": {
6+
"name": "info@optimization.team",
7+
"email": "info@optimization.team",
8+
"web": "optimization.team"
9+
},
10+
"keywords": ["Cache", "IndexedDB", "Cache API", "CacheStorage", "keyvalue", "keyval", "key/value"],
11+
12+
"homepage": "https://github.com/optimalisatie/",
13+
"copyright": "Copyright (C) 2018 Optimization.Team, Utrecht, NLD",
14+
"main": "cache-api-keyval.js",
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/optimalisatie/exec.js.git"
18+
},
19+
"engines": {
20+
"node": "~0.10"
21+
},
22+
"dependencies": {
23+
24+
},
25+
"devDependencies": {
26+
"grunt": "latest",
27+
"grunt-closure-compiler": "latest",
28+
"matchdep": "latest",
29+
"merge": "latest"
30+
}
31+
}

0 commit comments

Comments
 (0)