|
2 | 2 |
|
3 | 3 | A cache manager evening out the W3C's localStorage and IE's userData.
|
4 | 4 |
|
| 5 | + |
5 | 6 | == What's new in this release?
|
6 | 7 |
|
7 | 8 | See the CHANGELOG file for information on what's new.
|
8 | 9 |
|
| 10 | + |
| 11 | +== Requirements |
| 12 | + |
| 13 | +A browser that supports caching via userData or localStorage. |
| 14 | + |
| 15 | +Note: if the browser doesn't support these features, Squirrel will not |
| 16 | +be active, but it won't throw an error. |
| 17 | + |
| 18 | + |
9 | 19 | == Installation/Usage
|
10 | 20 |
|
11 | 21 | Put Squirrel.js in a directory on your website, e.g. /js.
|
12 | 22 |
|
13 | 23 | Then create a new Squirrel, passing it an id for your cache (which should
|
14 | 24 | be unique for your application):
|
15 | 25 |
|
16 |
| -`var $S = new Squirrel( 'scale-song' );` |
| 26 | +var $S = new Squirrel( 'scale-song' ); |
17 | 27 |
|
18 | 28 | In IE, you can optionally supply a second argument for the number of
|
19 | 29 | seconds you want the cache to live:
|
20 | 30 |
|
21 |
| -`var $S = new Squirrel( 'scale-song', 10080 ); // store one week` |
| 31 | +var $S = new Squirrel( 'scale-song', 10080 ); // store one week |
22 | 32 |
|
23 | 33 | You can use Squirrel to store and retrieve info from the cache:
|
24 | 34 |
|
25 |
| -`$S.write( 'doe', 'ray' );` |
26 |
| -`$S.read( 'doe' ); // 'ray'` |
| 35 | +$S.write( 'doe', 'ray' ); |
| 36 | +$S.read( 'doe' ); // 'ray' |
27 | 37 |
|
28 | 38 | You can even create sub-caches by supplying an optional string to beginning
|
29 | 39 | of these methods:
|
30 | 40 |
|
31 |
| -`$S.write( 'song', 'doe', 'a dear, a female dear' );` |
32 |
| -`$S.read( 'doe' ); // 'ray'` |
33 |
| -`$S.read( 'song', 'doe' ); // 'a dear, a female dear'` |
| 41 | +$S.write( 'song', 'doe', 'a dear, a female dear' ); |
| 42 | +$S.read( 'doe' ); // 'ray' |
| 43 | +$S.read( 'song', 'doe' ); // 'a dear, a female dear' |
34 | 44 |
|
35 | 45 | With Squirrel, you can also clean up the cache using one of two methods:
|
36 |
| -`remove()` (for individual keys) or `clear()` (for the cache or sub-caches): |
| 46 | +remove() (for individual keys) or clear() (for the cache or sub-caches): |
37 | 47 |
|
38 | 48 | // removing a single property from a sub-cache
|
39 |
| -`$S.remove( 'song', 'doe' );` |
40 |
| -`$S.read( 'song', 'doe' ); // null` |
41 |
| -`$S.read( 'doe' ); // 'ray'` |
| 49 | +$S.remove( 'song', 'doe' ); |
| 50 | +$S.read( 'song', 'doe' ); // null |
| 51 | +$S.read( 'doe' ); // 'ray' |
42 | 52 |
|
43 | 53 | // clearing a sub-cache
|
44 |
| -`$S.write( 'song', 'doe', 'a dear, a female dear' );` |
45 |
| -`$S.write( 'song', 'ray', 'a drop of golden sun' );` |
46 |
| -`$S.clear( 'song' );` |
47 |
| -`$S.read( 'song', 'doe' ); // null` |
48 |
| -`$S.read( 'song', 'ray' ); // null` |
49 |
| -`$S.read( 'doe' ); // 'ray'` |
| 54 | +$S.write( 'song', 'doe', 'a dear, a female dear' ); |
| 55 | +$S.write( 'song', 'ray', 'a drop of golden sun' ); |
| 56 | +$S.clear( 'song' ); |
| 57 | +$S.read( 'song', 'doe' ); // null |
| 58 | +$S.read( 'song', 'ray' ); // null |
| 59 | +$S.read( 'doe' ); // 'ray' |
50 | 60 |
|
51 | 61 | // removing a property form the main cache
|
52 |
| -`$S.remove( 'doe' );` |
53 |
| -`$S.read( 'doe' ); // null` |
| 62 | +$S.remove( 'doe' ); |
| 63 | +$S.read( 'doe' ); // null |
54 | 64 |
|
55 | 65 | // clearing the whole cache
|
56 |
| -`$S.write( 'doe', 'ray' );` |
57 |
| -`$S.write( 'song', 'doe', 'a dear, a female dear' );` |
58 |
| -`$S.write( 'song', 'ray', 'a drop of golden sun' );` |
59 |
| -`$S.clear();` |
60 |
| -`$S.read( 'song', 'doe' ); // null` |
61 |
| -`$S.read( 'song', 'ray' ); // null` |
62 |
| -`$S.read( 'doe' ); // null` |
| 66 | +$S.write( 'doe', 'ray' ); |
| 67 | +$S.write( 'song', 'doe', 'a dear, a female dear' ); |
| 68 | +$S.write( 'song', 'ray', 'a drop of golden sun' ); |
| 69 | +$S.clear(); |
| 70 | +$S.read( 'song', 'doe' ); // null |
| 71 | +$S.read( 'song', 'ray' ); // null |
| 72 | +$S.read( 'doe' ); // null |
| 73 | + |
63 | 74 |
|
64 | 75 | == The distribution
|
65 | 76 |
|
66 | 77 | Besides the Squirrel.js files in /src, there's a complete
|
67 | 78 | test tree included (/tests) which holds assorted tests for Squirrel.js
|
68 | 79 | and a minified version in /min.
|
69 | 80 |
|
| 81 | + |
70 | 82 | == License
|
71 | 83 |
|
72 | 84 | Squirrel.js is licensed under the terms of the MIT License, see
|
|
0 commit comments