Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

apollo-server-caching

Package Overview
Dependencies
1
Maintainers
1
Versions
56
Issues
File Explorer

Advanced tools

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/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apoll

    3.3.0latest

Version published
Maintainers
1
Weekly downloads
1,613,339
decreased by-28.02%

Weekly downloads

Changelog

Source

v3.3.0

  • apollo-server-core: Error handling when a serverWillStop callback invoked by server.stop() (or gateway.stop()) throws is now consistent: the original call to server.stop() throws the error, and any concurrent and subsequent calls to server.stop() throw the same error. Prior to Apollo Server v2.22.0, the original call threw the error and the behavior of concurrent and subsequent calls was undefined (in practice, it would call shutdown handlers a second time). Apollo Server v2.22.0 intended to put these semantics into place where all three kinds of calls would throw, but due to bugs, the original call would return without error and concurrent calls would hang. (Subsequent calls would correctly throw the error.) In addition, errors thrown by the drainServer hook introduced in Apollo Server v3.2.0 are now handled in the same way. Issue #5649 PR #5653

Readme

Source

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

FAQs

What is 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/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apoll

Is apollo-server-caching popular?

The npm package apollo-server-caching receives a total of 1,178,056 weekly downloads. As such, apollo-server-caching popularity was classified as popular.

Is apollo-server-caching well maintained?

We found that apollo-server-caching demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 05 Nov 2021
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc