A simple caching object with TTL
<script src="/path/to/active-cache.js"></script>
Download the latest standalone JavaScript files (ES5)
new ActiveCache(options?)
- options (optional)
- Type: Object
- The options for the caching. Check out the available options.
const activeCache = new ActiveCache({prefix: 'c', stTTL: null});
activeCache.set("myKey", "A value", 60);
// After 40 minutes:
activeCache.get("myKey")
//=> {value: "myKey", ttl: 1575952773409}
// After 1 hour:
activeCache.get("myKey")
//=> null
The ActiveCache class also support multiple optional configurations. These should be passed as an object to the ActiveCache class object. If no manual configurations are set, default options are used.
- Type:
Boolean
- Default:
null
Standard time to live. null
= unlimited time.
- Type:
String
- Default:
c
The prefix is used for all keys in the stored in SessionStorage, on the form prefix:key
.
-
key:
- Type:
String
- Key for storing the value.
- Type:
-
value:
- Type:
- Any value that can be converted to JSON.
- Type:
-
ttl:
- Type:
Number
ornull
- "Time to live", the time a cache object is valid.
null
= unlimited time.
- Type:
-
(return value):
- Type:
Boolean
- Returns true if the entry was successfully stored. False otherwise.
- Type:
Sets a key
value
pair.
-
key:
- Type:
String
- Key for storing the value.
- Type:
-
(return value):
- Type:
Object
- Returns the item stored by the provided key.
- Type:
Gets an item on the form {value: "value", ttl: 1575952773409}
, stored by a given key
.
-
key:
- Type:
String
- Key for the entry to be deleted.
- Type:
-
(return value):
- Type:
Object
- Returns the item stored by the provided key.
- Type:
Deletes an entry with the given key
.
Deletes all entries stored by the ActiveCache with the currently used prefix
.
Clone a copy of the main active-cache git repo by running:
git clone git://github.com/andstor/active-cache.git
Enter the active-cache directory and run the build script:
npm run build