New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apollo-server-cache-sql

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-cache-sql

Minimalistic Apollo Server SQL Cache driver

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

Apollo Server SQL Cache driver

npm version Build and Deploy codecov Codacy Badge code style: prettier npm

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.

CREATE TABLE `cache` (
  `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

import mysql from 'mysql';
import { SqlCache } from 'apollo-server-cache-sql';

// Setup the connection client
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'me',
  password: 'secret',
  database: 'my_db',
});
connection.connect();

// Setup Apollo Server with SQL cache driver
const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new SqlCache({
    client: connection,
    databaseName: 'my_db',
    tableName: 'cache',
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});

Usage with full-query caching

import mysql from 'mysql';
import { SqlCache } from 'apollo-server-cache-sql';
import responseCachePlugin from 'apollo-server-plugin-response-cache';

// Setup the connection client
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'me',
  password: 'secret',
  database: 'my_db',
});
connection.connect();

// Setup Apollo Server with SQL cache driver
const server = new ApolloServer({
  // ...
  plugins: [
    responseCachePlugin({
      cache: new SqlCache({
        client: connection,
        databaseName: 'my_db',
        tableName: 'cache',
      }),
    }),
  ],
});

FAQs

Package last updated on 25 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc