Class: Server

Server

new Server(client, configopt)

Create a new instance of the server interface.
Parameters:
Name Type Attributes Description
client RedisClient
config Object <optional>
configuration values. See Server#_configure
Source:

Methods

(private) _configure(configopt)

Configure the instance
Parameters:
Name Type Attributes Description
config Object <optional>
configuration values
Properties
Name Type Attributes Description
key String <optional>
key to use in Redis
min_size Number <optional>
minimum size of a filled cache
max_size Number <optional>
maximum size of a filled cache
stringify function <optional>
function for stringifying objects
Source:

(private) _reduce()

Reduce the cache size to respect maximum limit. This means that at any time, the maximum size the cache can grow to is . Whenever the size of the cache reaches this upper bound, it is reduced to . This helps avoid requests that will return 0 items after a size reduction. This function queries the cache on each request. A possible speed up would be have the cache alert the application when maximum size is reached, thus calling this function only when it is needed (and not on each request to add items to cache). Actually, it might happen to fewer times than that as we are debouncing requests in this app process. All functions adding items to the cache call this function thus ensuring the cache does not grow out of bounds.
Source:
To Do:
  • handle errors that are being ignored

(private) _wrapCallback(callbackopt) → {function}

Wrap callback for user. This allows us to add several hooks in one place, to be executed just before we return the response to the callee. These hooks include reducing the cache (when necessary).
Parameters:
Name Type Attributes Description
callback function <optional>
user's callback
Source:
Returns:
wrapped callback
Type
function

add(items, callbackopt)

Add several items to the cache. These is an array of object, each with an ID (.id prop) that defines its position in the ordered sequence of all items.
Parameters:
Name Type Attributes Description
items Array.<Object> array of items
Properties
Name Type Description
id Number id of the item
callback function <optional>
callback(err)
Source:

addOne(idopt, item, callbackopt)

Add one item to the cache. Ths ID is represents its position in the ordered sequence of all items.
Parameters:
Name Type Attributes Description
id Number <optional>
id of the item
item Object | String the item itself
callback function <optional>
callback(err)
Source:

getSize(callback)

Return the size of the cache i.e. number of items in the cache. Note that this function queries the redis server to determine this size and it is therefore not stored in process memory. This ensure a consistent value across multiple application instances using a single redis server DB.
Parameters:
Name Type Description
callback function callback(err, size)
Source:

purge(callbackopt)

Purge the cache. This destroys your cache's items and its existence in the backing store. This might be useful if your want to reclaim memory in Redis. This function is DANGEROUS. How? If on app startup, we decide to be purging the cache, it would mean that anytime a new application is started, the cache is purged. Such random purges may cause host instability due to the numerous creation and purges requests (especially if we are starting multiple instances at once). It is therefore recommended that you only purge cache when you intend to do so. For example, from an admin panel, you can purge the cache (maybe the cache for the host is misbehaving or during debugging).
Parameters:
Name Type Attributes Description
callback function <optional>
callback(err)
Source:

removeOne(id, callbackopt)

Remove one item from the cache. This ID represents its position in the ordered sequence of all items.
Parameters:
Name Type Attributes Description
id Number id of the item
callback function <optional>
callback(err)
Source: