| 
1 |  | -## Usage  | 
 | 1 | +## Quickstart  | 
2 | 2 | 
 
  | 
3 | 3 | ```js  | 
4 |  | -const Cache = require('cache-base');  | 
 | 4 | +const CacheBase = require('cache-base');  | 
 | 5 | +const app = new CacheBase();  | 
 | 6 | + | 
 | 7 | +app.set('a.b', 'c');  | 
 | 8 | + | 
 | 9 | +console.log(app.cache.a); //=> { b: 'c' }  | 
 | 10 | +console.log(app.cache.a.b); //=> 'c'  | 
 | 11 | + | 
 | 12 | +console.log(app.get('a')); //=> { b: 'c' }  | 
 | 13 | +console.log(app.get('a.b')); //=> 'c'  | 
5 | 14 | ```  | 
6 | 15 | 
 
  | 
7 |  | -**Instantiate**  | 
 | 16 | +More [usage examples](#usage-examples) below.  | 
 | 17 | + | 
 | 18 | + | 
 | 19 | +## API  | 
 | 20 | + | 
 | 21 | +{%= apidocs("index.js") %}  | 
 | 22 | + | 
 | 23 | + | 
 | 24 | +## Usage examples  | 
 | 25 | + | 
 | 26 | +**Create an instance of cache-base**  | 
8 | 27 | 
 
  | 
9 | 28 | ```js  | 
10 |  | -// instantiate  | 
11 |  | -const cache = new Cache();  | 
 | 29 | +const app = new CacheBase();  | 
12 | 30 | 
 
  | 
13 |  | -// set values  | 
14 |  | -cache.set('a', 'b');  | 
15 |  | -cache.set('c.d', 'e');  | 
 | 31 | +app.set('a', 'b');  | 
 | 32 | +app.set('c.d', 'e');  | 
16 | 33 | 
 
  | 
17 |  | -// get values  | 
18 |  | -console.log(cache.get('a'));  | 
 | 34 | +console.log(app.get('a'));  | 
19 | 35 | //=> 'b'  | 
20 |  | -console.log(cache.get('c'));  | 
 | 36 | +console.log(app.get('c'));  | 
21 | 37 | //=> { d: 'e' }  | 
22 |  | -console.log(cache);  | 
23 |  | -//=> Cache { a: 'b' }  | 
 | 38 | +console.log(app);  | 
 | 39 | +//=> CacheBase { a: 'b' }  | 
24 | 40 | ```  | 
25 | 41 | 
 
  | 
26 | 42 | **Initialize with an object**  | 
27 | 43 | 
 
  | 
28 | 44 | ```js  | 
29 |  | -// instantiate  | 
30 |  | -const cache = new Cache({ a: 'b', c: { d: 'e' } });  | 
 | 45 | +const app = new CacheBase({ a: 'b', c: { d: 'e' } });  | 
31 | 46 | 
 
  | 
32 |  | -// get values  | 
33 |  | -console.log(cache.get('a'));  | 
 | 47 | +console.log(app.get('a'));  | 
34 | 48 | //=> 'b'  | 
35 |  | -console.log(cache.get('c'));  | 
 | 49 | +console.log(app.get('c'));  | 
36 | 50 | //=> { d: 'e' }  | 
37 |  | -console.log(cache.get('c.d'));  | 
 | 51 | +console.log(app.get('c.d'));  | 
38 | 52 | //=> 'e'  | 
39 |  | -console.log(cache);  | 
40 |  | -//=> Cache { a: 'b' }  | 
 | 53 | +console.log(app);  | 
 | 54 | +//=> CacheBase { cache: { a: 'b' } }  | 
41 | 55 | ```  | 
42 | 56 | 
 
  | 
43 | 57 | **Inherit**  | 
44 | 58 | 
 
  | 
45 | 59 | ```js  | 
46 |  | -class MyApp extends Cache {}  | 
 | 60 | +class MyApp extends CacheBase {}  | 
47 | 61 | 
 
  | 
48 |  | -var cache = new MyApp();  | 
49 |  | -cache.set('a', 'b');  | 
50 |  | -console.log(cache.get('a'));  | 
 | 62 | +const app = new MyApp();  | 
 | 63 | +app.set('a', 'b');  | 
 | 64 | +app.set('c', 'd');  | 
 | 65 | + | 
 | 66 | +console.log(app.get('a'));  | 
51 | 67 | //=> 'b'  | 
 | 68 | + | 
 | 69 | +console.log(app);  | 
 | 70 | +//=> MyApp { cache: { a: 'b', c: 'd' } }  | 
52 | 71 | ```  | 
53 | 72 | 
 
  | 
54 | 73 | **Custom namespace**  | 
55 | 74 | 
 
  | 
56 |  | -Define a custom property name for storing values. By default, values are stored directly on the instance (for example, when `cache.set('foo', 'bar')` is used, `cache.foo` would be `bar`).  | 
 | 75 | +Pass a string as the first value to the contructor to define a custom property name to use for the cache. By default values are stored on the `cache` property.  | 
57 | 76 | 
 
  | 
58 | 77 | ```js  | 
59 |  | -const Cache = require('cache-base');  | 
60 |  | -const cache = new Cache('data', { a: 'b' });  | 
61 |  | -cache.set('c.d', 'e');  | 
 | 78 | +const CacheBase = require('cache-base');  | 
 | 79 | +const app = new CacheBase('data', { a: 'b' });  | 
 | 80 | +app.set('c.d', 'e');  | 
62 | 81 | 
 
  | 
63 | 82 | // get values  | 
64 |  | -console.log(cache.get('a'));  | 
 | 83 | +console.log(app.get('a'));  | 
65 | 84 | //=> 'b'  | 
66 |  | -console.log(cache.get('c'));  | 
 | 85 | +console.log(app.get('c'));  | 
67 | 86 | //=> { d: 'e' }  | 
68 |  | -console.log(cache.data);  | 
 | 87 | +console.log(app.data);  | 
69 | 88 | //=> { a: 'b', c: { d: 'e' } }  | 
70 |  | -console.log(cache);  | 
71 |  | -//=> Cache { data: { a: 'b', c: { d: 'e' } } }  | 
 | 89 | +console.log(app);  | 
 | 90 | +//=> CacheBase { data: { a: 'b', c: { d: 'e' } } }  | 
72 | 91 | ```  | 
73 |  | - | 
74 |  | -## API  | 
75 |  | - | 
76 |  | -{%= apidocs("index.js") %}  | 
 | 
0 commit comments