@expo/entity-cache-adapter-local-memory
TypeScript icon, indicating that this package has built-in type declarations

0.35.0 • Public • Published

@expo/entity-cache-adapter-local-memory

Cross-request LRU cache adapter for @expo/entity. Use this cache with caution - it is nonstandard. The cache is shared between requests in the node process.

Note: This uses version 6.0.0 of node-lru-cache since it the most tuned version for our use case (low TTL + LRU). Upgrading to 7.x will cause high memory usage for the entity cache adapter use case since it allocates fixed-size data structures up front to tune for the non-TTL use case: https://github.com/isaacs/node-lru-cache/issues/208.

Documentation

Why NOT use this cache

Because this is an in-memory cache, cross-machine invalidation is not possible. Do not use this cache if you have the following use cases:

  • The objects stored are mutable
  • Reading a stale object from the cache is not acceptable in your application
  • Cross-machine invalidation is not possible

Typical use cases

If your application sees many requests fetching the same objects, you can save a trip to your cache cluster and backing datastore by using this in-memory cache. Here are some good use cases:

  • The objects stored are mostly immutable, and reading a stale object for a short TTL is acceptable
  • You have a low TTL setting in your cache

Usage

During EntityCompanionProvider instantiation:

export const createDefaultEntityCompanionProvider = (
  metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
): EntityCompanionProvider => {
  return new EntityCompanionProvider(
    metricsAdapter,
    {
      ...
    },
    {
      ['local-memory']: {
        cacheAdapterProvider: new LocalMemoryCacheAdapterProvider.getProvider(),
      },
    }
  );
};

Readme

Keywords

Package Sidebar

Install

npm i @expo/entity-cache-adapter-local-memory

Weekly Downloads

345

Version

0.35.0

License

MIT

Unpacked Size

68.4 kB

Total Files

31

Last publish

Collaborators

  • szdziedzic
  • alanhughes
  • kadikraman
  • radoslawkrzemien
  • aleqsio
  • marklawlor
  • gabrieldonadel
  • simek
  • keith-kurak
  • christopherwalter
  • kbrandwijk
  • fiber-god
  • ide
  • brentvatne
  • evanbacon
  • quinlanj
  • expoadmin
  • tsapeta
  • exponent
  • wschurman
  • wkozyra
  • bycedric
  • lukmccall
  • jonsamp
  • princefleaswallow
  • kudochien