apollo-server/packages/apollo-server-caching
2018-06-21 15:33:07 -07:00
..
src Typescript Improvements and esModuleInterop fix (#1210) 2018-06-20 16:21:50 -07:00
.gitignore Add support for Redis and Memcached with ttls (#1191) 2018-06-18 19:36:51 -07:00
.npmignore Add support for Redis and Memcached with ttls (#1191) 2018-06-18 19:36:51 -07:00
package.json v2.0.0-rc.1 2018-06-21 15:33:07 -07:00
README.md Rename Memcached and Redis cache classes 2018-06-20 10:04:37 +02:00
tsconfig.json Move shared mocks to top-level and enforce noImplicitAny 2018-06-20 12:21:52 +02:00

Implementing your own Cache

Internally, Apollo Server uses the KeyValueCache interface to provide a caching store for the Data Sources. An in-memory LRU cache is used by default, and we provide connectors for Memcached/Redis backends.

Built with extensibility in mind, you can also implement your own cache to use with Apollo Server, in a way that best suits your application needs. It needs to implement the following interface that can be exported from apollo-server-caching:

export interface KeyValueCache {
  get(key: string): Promise<string | undefined>;
  set(key: string, value: string, options?: { ttl?: number }): Promise<void>;
}

Running test suite

You can export and run a jest test suite from apollo-server-caching to test your implementation:

// ../__tests__/YourKeyValueCache.test.ts

import YourKeyValueCache from '../src/YourKeyValueCache';
import { testKeyValueCache } from 'apollo-server-caching';
testKeyValueCache(new MemcachedCache('localhost'));

Run tests with jest --verbose