Skip to content

Commit 78720c1

Browse files
authored
Merge pull request #1103 from remotestorage/refactor/caching
Caching (config) improvements
2 parents bfc8fe3 + 4bf5239 commit 78720c1

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

doc/js-api/caching.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ List of functions
7070
7171
remoteStorage.caching.set('/bookmarks/archive/', 'SEEN');
7272
73+
.. autofunction:: Caching#checkPath(path)
74+
:short-name:
75+
76+
Example:
77+
78+
.. code:: javascript
79+
80+
remoteStorage.caching.checkPath('documents/').then(strategy => {
81+
console.log(`caching strategy for 'documents/': ${strategy}`));
82+
// "caching strategy for 'documents/': SEEN"
83+
});
84+
7385
.. autofunction:: Caching#reset
7486
:short-name:
7587

test/unit/caching-suite.js

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if (typeof define !== 'function') {
22
var define = require('amdefine')(module);
33
}
44

5-
define(['require', 'fs'], function(require, fs, undefined) {
5+
define(['require'], function(require) {
66
var suites = [];
77

88
suites.push({
@@ -92,15 +92,22 @@ define(['require', 'fs'], function(require, fs, undefined) {
9292
desc: "#set() sets caching settings for given path and subtree",
9393
run: function(env, test) {
9494
env.caching.set('/foo/', 'FLUSH');
95-
test.assertAnd(env.caching.checkPath('/'), 'SEEN');
96-
test.assertAnd(env.caching.checkPath('/bar'), 'SEEN');
97-
test.assertAnd(env.caching.checkPath('/bar/'), 'SEEN');
98-
test.assertAnd(env.caching.checkPath('/bar/foo'), 'SEEN');
99-
test.assertAnd(env.caching.checkPath('/foo/'), 'FLUSH');
100-
test.assertAnd(env.caching.checkPath('/foo/bar'), 'FLUSH');
101-
test.assertAnd(env.caching.checkPath('/foo/bar/'), 'FLUSH');
102-
test.assertAnd(env.caching.checkPath('/foo/bar/baz'), 'FLUSH');
103-
test.assertAnd(env.caching.checkPath('/foo/bar/baz/'), 'FLUSH');
95+
96+
let config = {
97+
'/': 'SEEN',
98+
'/bar': 'SEEN',
99+
'/bar/': 'SEEN',
100+
'/bar/foo': 'SEEN',
101+
'/foo/': 'FLUSH',
102+
'/foo/bar': 'FLUSH',
103+
'/foo/bar/': 'FLUSH',
104+
'/foo/bar/baz': 'FLUSH',
105+
'/foo/bar/baz/': 'FLUSH'
106+
};
107+
108+
for (let path in config) {
109+
test.assertAnd(env.caching.checkPath(path), config[path]);
110+
}
104111
test.done();
105112
}
106113
},
@@ -120,25 +127,31 @@ define(['require', 'fs'], function(require, fs, undefined) {
120127
env.caching.set('/foo/bar/baz/', 'FLUSH');
121128
env.caching.set('/foo/baf/', 'SEEN');
122129
env.caching.set('/bar/', 'FLUSH');
123-
test.assertAnd(env.caching.checkPath('/foo/'), 'ALL');
124-
test.assertAnd(env.caching.checkPath('/foo/1'), 'ALL');
125-
test.assertAnd(env.caching.checkPath('/foo/2/'), 'ALL');
126-
test.assertAnd(env.caching.checkPath('/foo/2/3'), 'ALL');
127-
test.assertAnd(env.caching.checkPath('/foo/bar/'), 'ALL');
128-
test.assertAnd(env.caching.checkPath('/foo/bar/baz/'), 'FLUSH');
129-
test.assertAnd(env.caching.checkPath('/foo/baf/'), 'SEEN');
130-
test.assertAnd(env.caching.checkPath('/foo/baf/1'), 'SEEN');
131-
test.assertAnd(env.caching.checkPath('/foo/baf/2/'), 'SEEN');
132-
test.assertAnd(env.caching.checkPath('/foo/baf/2/1/'), 'SEEN');
133-
test.assertAnd(env.caching.checkPath('/bar/'), 'FLUSH');
134-
test.assertAnd(env.caching.checkPath('/bar/1'), 'FLUSH');
135-
test.assertAnd(env.caching.checkPath('/bar/2/'), 'FLUSH');
136-
test.assertAnd(env.caching.checkPath('/bar/2/3/'), 'FLUSH');
137-
test.assertAnd(env.caching.checkPath('/'), 'SEEN');
138-
test.assertAnd(env.caching.checkPath('/1/'), 'SEEN');
139-
test.assertAnd(env.caching.checkPath('/2/'), 'SEEN');
140-
test.assertAnd(env.caching.checkPath('/2/3/'), 'SEEN');
141-
test.assertAnd(env.caching.checkPath('/2/3/'), 'SEEN');
130+
131+
let config = {
132+
'/foo/': 'ALL',
133+
'/foo/1': 'ALL',
134+
'/foo/2/': 'ALL',
135+
'/foo/2/3': 'ALL',
136+
'/foo/bar/': 'ALL',
137+
'/foo/bar/baz/': 'FLUSH',
138+
'/foo/baf/': 'SEEN',
139+
'/foo/baf/1': 'SEEN',
140+
'/foo/baf/2/': 'SEEN',
141+
'/foo/baf/2/1/': 'SEEN',
142+
'/bar/': 'FLUSH',
143+
'/bar/1': 'FLUSH',
144+
'/bar/2/': 'FLUSH',
145+
'/bar/2/3/': 'FLUSH',
146+
'/': 'SEEN',
147+
'/1/': 'SEEN',
148+
'/2/': 'SEEN',
149+
'/2/3/': 'SEEN',
150+
};
151+
152+
for (let path in config) {
153+
test.assertAnd(env.caching.checkPath(path), config[path]);
154+
}
142155
test.done();
143156
}
144157
},

0 commit comments

Comments
 (0)