apollo-server-caching

[![npm version](https://badge.fury.io/js/apollo-server-caching.svg)](https://badge.fury.io/js/apollo-server-caching) [![Build Status](https://circleci.com/gh/apollographql/apollo-server.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server)

This package is part of the legacy caching implementation used by Apollo Server v2 and v3, and is no longer maintained. We recommend you switch to the newer Keyv-based implementation (which is compatible with all versions of Apollo Server). See https://www.apollographql.com/docs/apollo-server/v3/performance/cache-backends#legacy-caching-implementation for more details.
Last updated 5 years ago by apollo-bot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install apollo-server-caching 
SYNC missed versions from official npm registry.

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>;
}

The ttl value for the set method's options is specified in seconds.

Testing cache implementations

Test helpers

apollo-server-caching exports a function that you can run within a test suite to validate your implementation. It throws on failure. If you want to test expiration, then mock out Date and setTimeout (probably with @sinonjs/fake-timers) and pass a tick can be called to advance the fake time. (If you don't pass tick, it won't test expiration.) Other than that, it has no dependencies and can work in any test system and shouldn't require any particular build configuration to use from jest. Here's an example of how to use it with jest:

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

import YourKeyValueCache from '../src/YourKeyValueCache';
import { runKeyValueCacheTests } from 'apollo-server-caching';
import FakeTimers from '@sinonjs/fake-timers';

describe('YourKeyValueCache', () => {
  it('run apollo-server-caching test suite', async () => {
    const cache = new YourKeyValueCache();
    const clock = FakeTimers.install();
    try {
      await runKeyValueCacheTests(cache, (ms: number) => clock.tick(ms));
    } finally {
      clock.uninstall();
      await cache.close();
    }
  });
});

For more details, consult the source for apollo-server-caching.

Running tests

Run tests with jest --verbose

Current Tags

  • 3.2.0-alpha.0                                ...           alpha (3 years ago)
  • 3.3.0                                ...           latest (3 years ago)
  • 3.1.0                                ...           next (3 years ago)
  • 0.300.0-alpha.3                                ...           next-v3 (4 years ago)
  • 3.0.0-preview.1                                ...           preview (3 years ago)
  • 3.0.0-rc.0                                ...           rc (3 years ago)
  • 0.6.1-unified2.0                                ...           unified (4 years ago)

56 Versions

  • 3.3.0 [deprecated]           ...           3 years ago
  • 3.2.0 [deprecated]           ...           3 years ago
  • 3.2.0-alpha.0 [deprecated]           ...           3 years ago
  • 3.1.0 [deprecated]           ...           3 years ago
  • 3.1.0-alpha.0 [deprecated]           ...           3 years ago
  • 3.0.1 [deprecated]           ...           3 years ago
  • 3.0.0 [deprecated]           ...           3 years ago
  • 3.0.0-rc.0 [deprecated]           ...           3 years ago
  • 3.0.0-preview.1 [deprecated]           ...           3 years ago
  • 0.300.0-preview.0 [deprecated]           ...           3 years ago
  • 0.300.0-alpha.4 [deprecated]           ...           4 years ago
  • 0.7.0 [deprecated]           ...           4 years ago
  • 0.7.0-alpha.0 [deprecated]           ...           4 years ago
  • 0.6.1-unified2.0 [deprecated]           ...           4 years ago
  • 0.6.1-unified.0 [deprecated]           ...           4 years ago
  • 0.6.0 [deprecated]           ...           4 years ago
  • 0.6.0-alpha.0 [deprecated]           ...           4 years ago
  • 0.5.3 [deprecated]           ...           4 years ago
  • 0.300.0-alpha.3 [deprecated]           ...           4 years ago
  • 0.300.0-alpha.2 [deprecated]           ...           4 years ago
  • 0.5.2 [deprecated]           ...           4 years ago
  • 0.5.1 [deprecated]           ...           5 years ago
  • 0.5.0 [deprecated]           ...           5 years ago
  • 0.4.1-alpha.13 [deprecated]           ...           5 years ago
  • 0.4.1-alpha.1 [deprecated]           ...           5 years ago
  • 0.4.1-alpha.0 [deprecated]           ...           5 years ago
  • 0.4.0 [deprecated]           ...           6 years ago
  • 0.4.0-alpha.1 [deprecated]           ...           6 years ago
  • 0.4.0-alpha.0 [deprecated]           ...           6 years ago
  • 0.3.1 [deprecated]           ...           6 years ago
  • 0.3.1-rc.0 [deprecated]           ...           6 years ago
  • 0.3.0 [deprecated]           ...           6 years ago
  • 0.2.2 [deprecated]           ...           6 years ago
  • 0.3.0-alpha.2 [deprecated]           ...           6 years ago
  • 0.3.0-alpha.1 [deprecated]           ...           6 years ago
  • 0.3.0-alpha.0 [deprecated]           ...           6 years ago
  • 0.2.1 [deprecated]           ...           6 years ago
  • 0.2.0 [deprecated]           ...           6 years ago
  • 0.2.0-alpha.2 [deprecated]           ...           6 years ago
  • 0.2.0-alpha.1 [deprecated]           ...           6 years ago
  • 0.2.0-alpha.0 [deprecated]           ...           6 years ago
  • 0.2.0-register.2195 [deprecated]           ...           6 years ago
  • 0.1.2 [deprecated]           ...           6 years ago
  • 0.1.1 [deprecated]           ...           6 years ago
  • 0.1.0 [deprecated]           ...           6 years ago
  • 0.1.0-rc.11 [deprecated]           ...           6 years ago
  • 0.1.0-rc.10 [deprecated]           ...           6 years ago
  • 0.1.0-rc.9 [deprecated]           ...           6 years ago
  • 2.0.0-rc.8 [deprecated]           ...           6 years ago
  • 2.0.0-rc.7 [deprecated]           ...           6 years ago
  • 2.0.0-rc.6 [deprecated]           ...           6 years ago
  • 2.0.0-rc.5 [deprecated]           ...           6 years ago
  • 2.0.0-rc.3 [deprecated]           ...           6 years ago
  • 2.0.0-rc.2 [deprecated]           ...           6 years ago
  • 2.0.0-rc.1 [deprecated]           ...           6 years ago
  • 2.0.0-rc.0 [deprecated]           ...           6 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE