Skip to content

Commit

Permalink
Cache storage (#160)
Browse files Browse the repository at this point in the history
* bump react

* bump antdesign

* use sessionstorage for cache instead of react state

* with i could eslint templates :/
  • Loading branch information
jwkvam committed Nov 19, 2017
1 parent 2b734b5 commit 3b89edf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bowtie/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def save(key, value):
Parameters
----------
key : object
key : str
The key to determine where it's stored, you'll need this to load the value later.
value : object
The value to store in the cache.
Expand All @@ -39,7 +39,7 @@ def load(key):
Parameters
----------
key : object
key : str
The key to lookup the value stored.
Returns
Expand Down
6 changes: 3 additions & 3 deletions bowtie/src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"antd": "^2.13.9",
"antd": "^2.13.10",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
Expand All @@ -21,8 +21,8 @@
"normalize.css": "^7.0.0",
"postcss-modules-values": "^1.3.0",
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"sass-loader": "^6.0.6",
Expand Down
11 changes: 7 additions & 4 deletions bowtie/templates/index.jsx.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ class Dashboard extends React.Component {
saveValue = data => {
var arr = new Uint8Array(data['key']);
var key = msgpack.decode(arr);
this.cache[key] = data['data'];
var value = new Uint8Array(data['data']).toString();
sessionStorage.setItem('cache' + key, value);
}

loadValue = (data, fn) => {
var arr = new Uint8Array(data['data']);
var key = msgpack.decode(arr);
if (this.cache.hasOwnProperty(key)) {
fn(this.cache[key]);
} else {
var x = sessionStorage.getItem('cache' + key)
if (x === null) {
var buffer = new ArrayBuffer(1);
var x = new DataView(buffer, 0);
// msgpack encodes null to 0xc0
x.setUint8(0, 0xc0);
fn(buffer);
} else {
x = new Uint8Array(x.split(','));
fn(x.buffer);
}
}

Expand Down

0 comments on commit 3b89edf

Please sign in to comment.