Apollo Server SQL Cache driver
Minimalistic Apollo Server SQL Cache driver for times when Redis or other more modern caching solutions are too expensive or unavailable.
Installing
npm install --save-dev apollo-server-cache-sql# or yarn add -D apollo-server-cache-sql
Setup
A SQL table for cache artifact storage must be created. The following is a blueprint for a basic caching table.
( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(255) DEFAULT NULL, `value` longtext, `ttl` int(11) DEFAULT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Usage
;; // Setup the connection clientconst connection = mysql;connection; // Setup Apollo Server with SQL cache driverconst server = typeDefs resolvers cache: client: connection databaseName: 'my_db' tableName: 'cache' moviesAPI: ;
Usage with full-query caching
;;; // Setup the connection clientconst connection = mysql;connection; // Setup Apollo Server with SQL cache driverconst server = // ... plugins: ;