sequelize-redis-cache
sequelize-redis-cache copied to clipboard
Memcached porting..
Would be tough do a porting for memcached?
I don't believe it would be tough at all - might make sense to make this pluggable so the backend can be swapped in/out actually. Are you considering writing it?
@rfink yeah I'm strongly considering the idea to write it, I need it for memcached so would be great to have something covering both redis and memcache. What are your tips? Should we make a new repo? It's worth giving a brand new name, sequelize-redis-memcached sounds not that good hmm :)
var Memcached = require('memcached');
var Sequelize = require('sequelize');
var initCache = require('sequelize-redis-memcached'); // new module
var memcached = new Memcached('localhost:11211', {retries:10,retry:10000,remove:true,failOverServers:['192.168.0.103:11211']});
var db = new Sequelize('cache_tester', 'root', 'root', { dialect: 'mysql' });
var cacher = initCache(db, memcached);
PS. There's a typo in the README.md, initCacher instead of initCache. PPS. I'm done with the porting, it tooks me a few hours.
One idea is to have a separate repo, sequelize-memcached-cache or whatever makes sense. Another idea I have is something to the effect of 3 repos:
sequelize-cacher redis-simple-cache memcached-simple-cache
Redis & memcached simple cachers would expose the (Promise-ified) methods of set, get, and delete. Sequelize-cache would bootstrap a sequelize instance and accept either one as the cache "plugin". That way there wouldn't be duplicated code between repos, and then we could easily add a 3rd, 4th, etc (DynamoDB, file system, etc). Thoughts? I could stub out some pseudo code.
@rfink Take a look at what i made:
https://github.com/roccomuso/sequelize-cacher
Also tested and fully working, but there's a bit of code duplication.
Waiting for your review.. basically I've separated redis and memcached in 2 different layers, lib/redisLayer.js
and lib/memcachedLayer.js
.
The lib/index.js
based on the "engine" instance received will require the right layer.
@rfink File updated, and Travis-CI descriptor too, to instantiate also the memcached service.