0.0.4 • Published 8 years ago

bedrock-caches v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Bedrock Cache Collection

This is a collection of cache implementations for use in your application, e.g. for caching template data. Modules are seperated into several files so only the things you need get loaded.

A list of cache implementations:

  • In-memory cache
  • JSON object file cache
  • Cache wrapper for dynamic values

API

Caches implement the Cache<K, V> interface, which makes it easy to implement your own caches.

Almost all caches have a constructor in the form of:

new Cache(options)

Where the options object contains the following keys:

  • fetch: function that will be used to fetch a value if the value was not found in the cache

The following methods are available on all caches:

cache.get(key)

Get the value associated with key, doing a fetch if the value was not found.

cache.hasCached(key)

Checks if the value is added to the local cache.

cache.fetch(key)

Does a direct fetch for the given key. The value is not stored in the cache.

cache.evict(key)

Removes the value stored at key from the cache. Will not report an error if no values were found.

new MemoryCache(options)

Creates a new cache that will store values in-memory.

import { MemoryCache } from "bedrock-caches/lib/memory"

new JSONFileCache(options)

Creates a new cache that serializes values onto disk.

  • cacheDir the directory to store the serialized objects
import { JSONFileCache } from "bedrock-caches/lib/json"

new UpdateCache(parentCache)

Creates a new cache that will listen to the change-event of its values and re-fetch as appropriate. The parentCache is used to store the values in.

import { UpdateCache } from "bedrock-caches/lib/update"

Limitations

  • Currently only supports synchronous caching
0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago