Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
apollo-server-caching
Advanced tools
Readme
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 theset
method'soptions
is specified in seconds.
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
.
Run tests with jest --verbose
FAQs
[![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/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apoll
The npm package apollo-server-caching receives a total of 573,135 weekly downloads. As such, apollo-server-caching popularity was classified as popular.
We found that apollo-server-caching demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.