nosql-cache

0.0.0 • Public • Published

Nosql Cache Build Status npm downloads license

Add the cache ability to the abstract-nosql database.

CacheNoSQL

  • CacheNoSQL(DatabaseClass[, options])
    • DatabaseClass: Provided with the AbstractNoSql database class.
    • options object
      • capacity: the max capacity size, defaults to unlimit. deletes the least-recently-used items if reached the capacity.
      • expires: the default expires time (milliscond), defaults to no expires time(<=0).
    • events:
      • 'add': triggle on a key is added.
      • 'update': triggle on a key is updated.
      • 'delete': triggle on a key is deleted from cache.

Cache

It can support secondary cache mechanism. the first level cache is fixed memory-resident always with the highest priority. the second level is the LRU cache.

the secondary LRU cache only available set the capacity of options or the key's expires time.

  • Cache(options|capacity):
    • options object
      • fixedCapacity: the first fixed cache max capacity size, defaults to unlimit.
      • capacity: the second LRU cache max capacity size, defaults to unlimit. deletes the least-recently-used items if reached the capacity. capacity > 0 to enable the secondary LRU cache.
      • expires: the default expires time (milliscond), defaults to no expires time(<=0). it will be put into LRU Cache if has expires time
    • events:
      • 'expired': triggle on a key is expired.

cache.set(key, value[,options|expires])

add/update key, value to cache.

  • options:
    • fixed (bool): set to first level fixed cache if true, defaults to false.
    • expires (int): expires time milliscond. defaults to never expired.

It will update the "recently used"-ness of the key if LRUCache enabled.

cache.setFixed(key, value)

add/update key,value to the first level fixed cache directly.

cache.setLRU(key, value[,expires])

add/update key,value to the secondary level LRU cache directly.

cache.get(key)

get the key from cache. it will fetch the key from the first fixed cache, fetch the key from the secondary cache if missing in the first cache.

It will update the "recently used"-ness of the key in the secondary cache if LRUCache enabled.

cache.getFixed(key)

get the key from the first level fixed cache directly.

cache.getLRU(key)

get the key from the secondary level LRU cache directly.

cache.peek(id)

get the key from cache. it will fetch the key from the first fixed cache, fetch the key from the secondary cache if missing in the first cache.

It will not update the "recently used"-ness in the secondary cache.

cache.peekLRU(id)

get the key from the secondary LRU cache directly.

It will not update the "recently used"-ness in the secondary cache.

cache.has(key)

the key whether exists in the cache.

cache.del(key)

cache.delete(key)

Deletes a key out of the cache.

cache.reset(options|capacity)

Clear the cache entirely and apply the new options.

  • options object
    • fixedCapacity: the first fixed cache max capacity size, defaults to unlimit.
    • capacity: the second LRU cache max capacity size, defaults to unlimit. deletes the least-recently-used items if reached the capacity. capacity > 0 to enable the secondary LRU cache.
    • expires: the default expires time (seconds), defaults to no expires time(<=0). it will be put into LRU Cache if has expires time

cache.clear()

cache.clean()

Clear the cache entirely.

cache.free()

free the first fixed cache and the secondary LRU cache.

Package Sidebar

Install

npm i nosql-cache

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • riceball