@qikdev/sdk 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,17 @@ var caches = {};
7
7
 
8
8
 
9
9
  /**
10
- * @classdesc A static service that provides tools for caching api requests and other information
10
+ * @classdesc Named in-memory caches shared by the whole page (LRU: the least recently used entries are dropped
11
+ * when a cache is full). The SDK keeps the content glossary in one; you can create your own to remember
12
+ * expensive lookups. Nothing is persisted: caches are lost on reload, and all of them are cleared on
13
+ * logout and organisation switch.
11
14
  * @alias cache
12
15
  * @class
13
16
  * @hideconstructor
17
+ * @example
18
+ * const cache = sdk.cache.get('my-lookups', { max: 100 });
19
+ * cache.set('answer', 42);
20
+ * cache.get('answer'); // 42
14
21
  */
15
22
  var QikCache = {
16
23
 
@@ -18,8 +25,12 @@ var QikCache = {
18
25
 
19
26
 
20
27
  /**
21
- * A helper function to reset all caches, useful if changing organisation or logging in or out as another user
22
- * @alias cache.reset
28
+ * Empties every cache created with sdk.cache.get (the caches themselves stay available, just empty).
29
+ * sdk.auth.logout() and sdk.auth.changeOrganisation() call this for you.
30
+ * @alias cache.reset
31
+ * @returns {undefined}
32
+ * @example
33
+ * sdk.cache.reset();
23
34
  */
24
35
  reset() {
25
36
  Object.entries(caches).forEach(([key, cache]) => {
@@ -34,10 +45,21 @@ var QikCache = {
34
45
  ///////////////////////////////////////////////////
35
46
 
36
47
  /**
37
- * A helper function to retrieve a specific cache
38
- * @alias cache.get
39
- * @param {string} key The key for the cache you want to retrieve
40
- * @return {LRUCache} The cache store for the specified key
48
+ * Returns the cache with this name, creating it the first time. Later calls with the same name return the
49
+ * same cache, whatever options they pass.
50
+ * @alias cache.get
51
+ * @param {String} key The cache's name.
52
+ * @param {Object} [options] lru-cache options, used only when the cache is created. Default { max: 5 } (five entries).
53
+ * @param {Number} [options.max] Maximum number of entries.
54
+ * @param {Number} [options.ttl] Milliseconds before an entry expires.
55
+ * @returns {LRUCache} An lru-cache instance: get(key), set(key, value), has(key), delete(key), clear().
56
+ * @example
57
+ * const cache = sdk.cache.get('people', { max: 500, ttl: 60000 });
58
+ * let person = cache.get(id);
59
+ * if (!person) {
60
+ * person = await sdk.content.get(id);
61
+ * cache.set(id, person);
62
+ * }
41
63
  */
42
64
  get(key, options) {
43
65
  options = options || {max:5};