mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
![]() - apollo-cache-control@0.2.2 - apollo-datasource-rest@0.1.3 - apollo-datasource@0.1.2 - apollo-engine-reporting-protobuf@0.0.1 - apollo-engine-reporting@0.0.2 - apollo-server-cache-memcached@0.1.2 - apollo-server-cache-redis@0.1.2 - apollo-server-caching@0.1.2 - apollo-server-cloudflare@2.0.0-rc.14 - apollo-server-core@2.0.2 - apollo-server-env@2.0.2 - apollo-server-errors@2.0.2 - apollo-server-express@2.0.2 - apollo-server-hapi@2.0.2 - apollo-server-integration-testsuite@2.0.2 - apollo-server-koa@2.0.2 - apollo-server-lambda@2.0.2 - apollo-server-micro@2.0.2 - apollo-server@2.0.2 - apollo-tracing@0.2.2 - graphql-extensions@0.1.2 |
||
---|---|---|
.. | ||
src | ||
.gitignore | ||
.npmignore | ||
package.json | ||
README.md | ||
tsconfig.json |
apollo-server-caching
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