-
Notifications
You must be signed in to change notification settings - Fork 0
Cookbook: cache
Eugene Lazutkin edited this page Nov 26, 2019
·
7 revisions
In order to use io.cache make sure that it is enabled:
// optional:
// set custom properties (can be done at any time)
io.cache.storage = io.cache.makeStorage('localStorage');
// defaults are sane, so you are unlikely to modify anything
// activate the package
io.cache.attach();See How to include for more details. See cache for the full documentation.
By default, all GET requests will be cached. How to opt-out?
var req = io.get({
url: 'abc',
cache: false
});
// not cachedio.cache.clear();var req1 = io.get('/abc'); // from server
// now it is cached
req = io.get('/abc'); // from cache
io.cache.remove('/abc');
req = io.get('/abc'); // from serverNote: io.cache.remove('/abc') removes only '/abc'. Other cached entries like '/abc?q=a' or '/abc/xyz' are left in the cache. If you want to remove them use a wildcard.
var req = io.get('/abc', {q: 1}); // from server
// now it is cached
io.cache.remove('/abc?*');
var req = io.get('/abc', {q: 1}); // from serverNote: io.cache.remove('/abc*') will remove all following cached entries:
'/abc''/abc?q=1''/abc/xyz''/abcd'
var req = io.get('/abc', {q: 1}); // from server
// now it is cached
// remove all cached resources, which URL has 'abc" in it as a word
// so it will remove '/abc' and '/xyz/abc?q=1' but not '/abcd'
io.cache.remove(/\babc\b/);
var req = io.get('/abc', {q: 1}); // from server