This package exports an implementation of KeyValueCache
that allows wrapping any other
Apollo KeyValueCache
implementation with a
configurable (default: zlib deflate
) compression layer. Its main goal is
to limit the amount of memory used by the caching environment and at the same time the amount of
data being in-transit from and to the caching environment.
const { RedisCache } = require('apollo-server-cache-redis');
const { CompressionCacheWrapper } = require('apollo-server-compression-cache-wrapper');
const 'zlib' = require('zlib');
const redisCache = new RedisCache({
host: 'redis-server',
});
const server = new ApolloServer({
typeDefs,
resolvers,
cache: new CompressionCacheWrapper(redisCache, {
compress: (data: Buffer) => zlib.deflateSync(data, { level: 1 }),
decompress: (data: Buffer) => zlib.inflateSync(data),
minimumCompressionSize: 262144,
}),
dataSources: () => ({
moviesAPI: new MoviesAPI(),
}),
});
-
compress (default:
zlib deflate
) - defines a custom compression method taking and returning aBuffer
. -
decompress (default:
zlib deflate
) - defines a custom decompression method taking and returning aBuffer
. - minimumCompressionSize (default: 262144) - defines minimal length of the data string, after exceeding which data proxied to wrapped cache are compressed before being passed forward.
For better performance monitor of CompressionCacheWrapper module in your app, run your app with DEBUG env.
To get all debug messages from all modules:
DEBUG=* npm run start
To get debug messages only from compression-wrapper module:
DEBUG=compression-wrapper npm run start