All Projects → DanielHreben → Sequelize Transparent Cache

DanielHreben / Sequelize Transparent Cache

Licence: cc-by-4.0
Simple to use and universal cache layer for Sequelize

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sequelize Transparent Cache

Easycaching
💥 EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
Stars: ✭ 1,047 (+664.23%)
Mutual labels:  redis, cache, caching, memcached
Scrapbook
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
Stars: ✭ 279 (+103.65%)
Mutual labels:  redis, cache, caching, memcached
Cachemanager
CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
Stars: ✭ 2,049 (+1395.62%)
Mutual labels:  redis, cache, caching, memcached
Cache
Cache library
Stars: ✭ 310 (+126.28%)
Mutual labels:  redis, cache, memcached
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+1484.67%)
Mutual labels:  redis, cache, memcached
Senparc.co2net
支持 .NET Framework & .NET Core 的公共基础扩展库
Stars: ✭ 289 (+110.95%)
Mutual labels:  redis, cache, memcached
Simple Spring Memcached
A drop-in library to enable memcached caching in Spring beans via annotations
Stars: ✭ 185 (+35.04%)
Mutual labels:  cache, caching, memcached
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+209.49%)
Mutual labels:  redis, cache, caching
React Component Caching
Speedier server-side rendering with component caching in React 16
Stars: ✭ 365 (+166.42%)
Mutual labels:  redis, caching, memcached
Libmc
Fast and light-weight memcached client for C++ / #python / #golang #libmc
Stars: ✭ 429 (+213.14%)
Mutual labels:  cache, caching, memcached
Weixinmpsdk
微信全平台 SDK Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 6.0。已支持微信公众号、小程序、小游戏、企业号、企业微信、开放平台、微信支付、JSSDK、微信周边等全平台。 WeChat SDK for C#.
Stars: ✭ 7,098 (+5081.02%)
Mutual labels:  redis, cache, memcached
Synchrotron
Caching layer load balancer.
Stars: ✭ 42 (-69.34%)
Mutual labels:  redis, cache, caching
Ansible Role Redis
Ansible Role - Redis
Stars: ✭ 176 (+28.47%)
Mutual labels:  redis, cache, memcached
Cachego
Golang Cache component - Multiple drivers
Stars: ✭ 148 (+8.03%)
Mutual labels:  redis, cache, memcached
Overlord
Overlord是哔哩哔哩基于Go语言编写的memcache和redis&cluster的代理及集群管理功能,致力于提供自动化高可用的缓存服务解决方案。
Stars: ✭ 1,884 (+1275.18%)
Mutual labels:  redis, cache, memcached
Stackexchange.redis.extensions
Stars: ✭ 419 (+205.84%)
Mutual labels:  redis, cache, caching
Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+1408.76%)
Mutual labels:  cache, caching, memcached
Aiocache
Asyncio cache manager for redis, memcached and memory
Stars: ✭ 496 (+262.04%)
Mutual labels:  redis, cache, memcached
Ansible Role Memcached
Ansible Role - Memcached
Stars: ✭ 54 (-60.58%)
Mutual labels:  cache, caching, memcached
Cash
HTTP response caching for Koa. Supports Redis, in-memory store, and more!
Stars: ✭ 122 (-10.95%)
Mutual labels:  redis, cache, caching

sequelize-transparent-cache

Build Status Coverage Status JavaScript Style Guide Code Climate npm version Dependency Status

Simple to use and universal cache layer for Sequelize.

  • Abstract: does not depends on underlying database, or cache specific
  • Transparent: objects returned from cache are regular Sequelize instances with all your methods
  • Explicit: all calls to cache comes through cache() method
  • Lightweight: zero additional dependencies

Installation

Install sequelize-transparent-cache itself:

npm install --save sequelize-transparent-cache

Find and install appropriate adaptor for your cache system, see "Available adaptors" section below. In this example we will use ioredis

npm install --save sequelize-transparent-cache-ioredis

Example usage

const Redis = require('ioredis')
const redis = new Redis()

const RedisAdaptor = require('sequelize-transparent-cache-ioredis')
const redisAdaptor = new RedisAdaptor({
  client: redis,
  namespace: 'model',
  lifetime: 60 * 60
})

const sequelizeCache = require('sequelize-transparent-cache')
const { withCache } = sequelizeCache(redisAdaptor)

const Sequelize = require('sequelize')
const sequelize = new Sequelize('database', 'user', 'password', {
  dialect: 'mysql',
  host: 'localhost',
  port: 3306
})

// Register and wrap your models:
// withCache() will add cache() methods to all models and instances in sequelize v4
const User = withCache(sequelize.import('./models/user'))

await sequelize.sync()

// Cache result of arbitrary query - requires cache key
await User.cache('active-users').findAll({
  where: {
    status: 'ACTIVE'
  }
})

// Create user in db and in cache
await User.cache().create({
  id: 1,
  name: 'Daniel'
})

// Load user from cache
const user = await User.cache().findByPk(1);

// Update in db and cache
await user.cache().update({
  name: 'Vikki'
})

Look for all examples applications in examples folder.

Methods

Object returned by cache() call contains wrappers for limited subset of sequelize model or instance methods.

Instance:

Model:

In addition, both objects will contain client() method to get cache adaptor.

Available adaptors

You can easy write your own adaptor. Each adaptor must implement 3 methods:

  • get(path: Array<string>): Promise<object>
  • set(path: Array<string>, value: object): Promise<void>
  • del(path: Array<string>): Promise<void>

Checkout existed adaptors for reference implementation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].