0.0.3 • Published 6 years ago

presence-cache v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

presence-cache

in-memory cache-like synchronous presence control

Why?

If you need basic synchronous cache for various reasons - eg. you don't want to use redis or you don't want to create your own class/prototype. This has originally been only a gist but recently got an update ^^

This cache is primariliy for presence control, you provide value and the cache tells you whether is already exists. But lets say, you have limited memory and process myriads of entries. Then you should probably clear the cache from time to time, even if that means that checking for specific value could return non-hit repeatedly during the runtime.

That's all covered in this module.

How to use

  • npm i presence-cache

  • const singletonCache = require('presence-cache).singleton

  • import { singletonCache }, PresenceCache from 'presence-cache'

The module yields a singleton as well as classic es6 class.

  • configuration:
    {
        maxSize: <number>, // max size of container. If the size reaches this value, it  will be swapped with secondary container
    }

How it works

Its just a basic data container(s) with additional logic, which holds key-value pairs. In this case, the key is and value is hardcoded TRUE. Because the maxSize can be reached at any time (and that means reset - we will normally lose the presence informations), the module works with 2 containers.

When the key is being checked, both containers are accessed. When the primary container is full, they are swapped - one is cleared and the second holds only the most recent keys. maxSize value is used for both containers.

This clearing process in fact replaces the timeout variable in classic cache, like redis, with the exception - key will be purged when there is no space left.

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago