apollo-server/packages/apollo-server-caching
Hugh Willson dd86fa8a29 Re-enable Typescript esModuleInterop (#1699)
`esModuleInterop` was enabled in
e4164c8892
to help with importing from packages that use default exports.
Those changes were reverted in
https://github.com/apollographql/apollo-server/pull/1210
to work around a few reported issues. Those issues are no longer
relevant, so this commit re-enables `esModuleInterop`, and
updates all default imports to use the more common (standard)
import syntax.
2018-09-21 16:43:33 +03:00
..
src Re-enable Typescript esModuleInterop (#1699) 2018-09-21 16:43:33 +03: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 Publish 2018-08-14 11:49:10 -07:00
README.md Rename apollo-server-redis and apollo-server-memcached 2018-07-18 18:30:09 -07:00
tsconfig.json Use strict top-level tsconfig and fix type issues or override per-package 2018-08-11 16:45:03 +02:00

apollo-server-caching

npm version Build Status

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