Class: Cache

Cache

Creates a new Cache instance.

new Cache(options, redisOptions){Cache}

cache.js, line 30
Name Type Description
options object

Cache options

redisOptions redisOptions

Redis client options.

Returns:
Type Description
Cache
  • The FireFerret Cache controller.

Methods

_getClient()

cache.js, line 48

Internal - Using this may induce unintended behaviors.

Returns:
An npm::redis client.

_setClient(client)

cache.js, line 40

Internal - Using this may induce unintended behaviors.

Name Type Description
client RedisClient

An npm::redis client that has already been connected.

bucketify(documents){Object}

cache.js, line 319

Determine which buckets need to be cached.

Name Type Description
documents Array

Array of MongoDB documents to cache.

Returns:
Type Description
Object

asyncclose(){void}

cache.js, line 91

Attempts to close the Redis client collection.

Returns:
Type Description
void

asyncconnect(){Promise}

cache.js, line 56

Attempts to establish a connection to Redis

Returns:
Type Description
Promise Resolves

debucketify(queryList){Object}

cache.js, line 346

Determine which buckets need to be retrieved.

Name Type Description
queryList Array

The list of document IDs.

Returns:
Type Description
Object The cache operations to carry out.

asyncgetDocument(documentID){String}

cache.js, line 185

Retrieve a single document from a bucket.

Name Type Description
documentID String

The document ID as a string.

Returns:
Type Description
String The document data.

asyncgetDocuments(queryList, options){Array|Stream}

cache.js, line 124

Retrieves cached documents from a queryList.

Name Type Default Description
queryList Array

The list of document IDs.

options Object {} optional
Name Type Default Description
hydrate boolean false optional

JSON.parse documents and attempt to reformat types (performance hit).

stream boolean false optional

Return as a stream.

ndjson boolean false optional

When streaming, use the ndJSON spec.

Returns:
Type Description
Array | Stream

asyncgetQueryHash(queryHash, query){String}

cache.js, line 263

Gets the document ID associated with a particular query

Name Type Description
queryHash String

The hash name version of a query.

query String

The query to retreive.

Returns:
Type Description
String The document ID.

asyncgetQueryList(queryKey){QueryMatch}

cache.js, line 227

Gets the queryList associated with the provided QueryKey

Name Type Description
queryKey QueryKey

The QueryKey

Returns:
Type Description
QueryMatch

asyncgetWideMatch(queryKey){Array|null}

cache.js, line 287

Attempts to find a previously cached query that contains our requested data.

Name Type Description
queryKey QueryKey

The QueryKey.

Returns:
Type Description
Array | null

asyncsetDocument(document, requestedID){void}

cache.js, line 199

Caches a single document into an appropriate bucket.

Name Type Description
document Object

The document to cache.

requestedID String | ObjectID

The document ID as a ObjectID instance or String.

Returns:
Type Description
void

asyncsetDocuments(queryKey, documents){void}

cache.js, line 153

Sets the queryList and caches documents into Redis.

Name Type Description
queryKey QueryKey

The QueryKey to use when caching.

documents Array

The documents to cache (from MongoDB).

Returns:
Type Description
void

asyncsetQueryHash(queryHash, args){void}

cache.js, line 275

Sets a key-value pair in the queryHash

Name Type Description
queryHash String

The hash name version of a query.

args any repeatable

The query-documentID pair to set.

Returns:
Type Description
void

asyncsetQueryList(queryKey, queryList){void}

cache.js, line 251

Sets the queryList

Name Type Description
queryKey QueryKey

The QueryKey.

queryList Array

The list of document IDs.

Returns:
Type Description
void