funny-bytes / sequelize-simple-cache Goto Github PK
View Code? Open in Web Editor NEWA simple, transparent, client-side, in-memory cache for Sequelize
A simple, transparent, client-side, in-memory cache for Sequelize
sequelize.import is deprecated in sequelize@6
Now I'm getting error: TypeError: sequelize.import is not a function
Sequelize document says, we should use require instead. How can we use it here?
Hello, I'm trying to cache just one model, but when I set everything up no logs come up, neither do errors. I can query all normally but I seen no logs with regards to caching.
This is how my setup code looks like:
const cache = new SequelizeSimpleCache({
DataStream: {ttl: 60*60} // 1 hour TTL
});
const Project = ProjectModel(sequelize);
const Measurement = MeasurementModel(sequelize);
//const DataStreamSeq = DataStreamModel(sequelize); // tried init both ways
//const DataStream = cache.init(DataStreamSeq);
const DataStream = cache.init(sequelize.import('./models/dataStream'));
const DataPoint = DataPointModel(sequelize, DataStream);
module.exports = {
Project,
Measurement,
DataStream,
DataPoint,
sequelize
};
And my DataStream model definition looks something like this:
class DataStream extends Model {
get objectId() {
return {id: this.id};
}
};
module.exports = (sequelize) => {
DataStream.init({
...
});
return DataStream;
};
Versions I'm using: "sequelize": "^5.21.2", "sequelize-simple-cache": "^1.0.4".
Thanks for any insight :)
5.2.6
to 5.2.7
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
sequelize is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 5 commits.
a676eea
fix(typings): upsert options (#10655)
ea5afbf
fix(model): map fields only once when saving (#10658)
33e140d
docs: fix typos (#10656)
580c065
test: typos in model test names (#10659)
46e0f68
docs: fix typo in belongs-to-many.js (#10652)
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Add the bulkCreate method to the list of methods that automatically clear the cache, just like create, update, etc.
there is a problem when we try to recache , it has not any tag so if i update my model it changes for everyone so other users need cache again you can add a specific id for cache Model . what do you say ?
thank you.
for example we user 1 and 2 .
user 1 updates his profile because it is not using specific tag for cache Model . it is doing the same for the user 2.
I did this in my dal layer file
` const cache = new SequelizeSimpleCache({
License: { ttl: false }, // cache for 1 day
}, {
debug: true,
ops: 60, // seconds
});
let checkConnection = async function () {
try {
await sequelize.authenticate();
} catch (error) {
logger.error("Unable to connect to the database:", error);
throw error;
}
}; `
and the function is also in dal layer file only...
let getAllLicenses = async function () { let licenses = await LicenseCache.findAll(); return licenses; };
but. the cache initializes
CACHE INIT { type: 'License', ttl: false, methods: [ 'findOne', 'findAndCountAll', 'findByPk', 'findAll', 'count', 'min', 'max', 'sum', 'find', 'findAndCount', 'findById', 'findByPrimary', 'all' ], methodsUpdate: [ 'create', 'bulkCreate', 'update', 'destroy', 'upsert', 'findOrBuild', 'insertOrUpdate', 'findOrInitialize', 'updateAttributes' ], limit: 50, clearOnUpdate: true, hit: 0, miss: 0, load: 0, purge: 0, ratio: NaN, size: { License: 0 } }
when i first call it it is a miss obviously and then it stores the data in cahce
CACHE OPS { hit: 4, miss: 6, load: 6, purge: 0, ratio: 0.4, size: { License: 6 } }
but then after a few seconds it cleans the cache
CACHE OPS { hit: 0, miss: 0, load: 0, purge: 0, ratio: NaN, size: { License: 0 } }
but ttl is false so cache should not be deleted
If a database query specifies a transaction, e.g.,
User.findOne({
where: { username: 'fred' },
transaction: t,
lock: true,
});
...caching does not make sense whatsoever.
Queries with transaction
should bypass caching completely.
In my case we are using a single node (it's actually an embedded process) so other parts of the code know explicitly when models are updated. Is there a way to invalidate certain model/ids when an update occurs?
I'm following the instructions provided and initiate the cache while defining my models:
// --- models/index.js ---
const SequelizeSimpleCache = require(`sequelize-simple-cache`);
const defineCategory = require(`./category`);
const defineComment = require(`./comment`);
const defineArticle = require(`./article`);
const defineArticleCategory = require(`./article-category`);
const Aliase = require(`./aliase`);
const cache = new SequelizeSimpleCache({
Article: {ttl: false}, // cache forever
Category: {ttl: false},
Comment: {ttl: false}
}, {
debug: true,
ops: 10,
});
module.exports = (sequelize) => {
const Category = defineCategory(sequelize);
const Comment = defineComment(sequelize);
const Article = defineArticle(sequelize);
const ArticleCategory = defineArticleCategory(sequelize);
cache.init(Category);
cache.init(Comment);
cache.init(Article);
Article.hasMany(Comment, {as: Aliase.COMMENTS, foreignKey: `articleId`});
Comment.belongsTo(Article, {as: Aliase.ARTICLE, foreignKey: `articleId`});
...
return {Category, Comment, Article, ArticleCategory};
};
Each model is located in a separate module and is defined via class:
// --- models/category.js ---
const {DataTypes, Model} = require(`sequelize`);
class Category extends Model {}
module.exports = (sequelize) => Category.init({
name: {
type: DataTypes.STRING,
allowNull: false
}
}, {
sequelize,
modelName: `Category`,
tableName: `categories`
});
When I start my server, the cache seems to accept my models:
CACHE INIT {
type: 'Category',
ttl: false,
methods: [
'findOne', 'findAndCountAll',
'findByPk', 'findAll',
'count', 'min',
'max', 'sum',
'find', 'findAndCount',
'findById', 'findByPrimary',
'all'
],
methodsUpdate: [
'create',
'bulkCreate',
'update',
'destroy',
'upsert',
'findOrBuild',
'insertOrUpdate',
'findOrInitialize',
'updateAttributes'
],
limit: 50,
clearOnUpdate: true,
hit: 0,
miss: 0,
load: 0,
purge: 0,
ratio: NaN,
size: { Category: 0 }
}
But while using app in dev mode the cache debug console remains the same:
CACHE OPS {
hit: 0,
miss: 0,
load: 0,
purge: 0,
ratio: NaN,
size: { Category: 0, Comment: 0, Article: 0 }
}
I assume the size key refers to the cached instances, but it's empty despite any queries made to DB.
I have tried to initiate cache just after my models are defined and before they are filled with mock data, the result is the same.
What am I doing wrong?
5.15.3
to 5.16.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
dfef227
Build: gensite passes rulesMeta to formatter rendering (#11567) (Kevin Partington)c06d38c
Fix: Allow HTML formatter to handle no meta data (#11566) (Ilya Volodin)87a5c03
Docs: func-style
: clarify when allowArrowFunctions
is used (#11548) (Oliver Joseph Ash)bc3e427
Update: pass rule meta to formatters RFC 10 (#11551) (Chris Meyer)b452f27
Chore: Update README to pull in reviewer data (#11506) (Nicholas C. Zakas)afe3d25
Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550) (Vernon de Goede)4fe7eb7
Chore: use nyc instead of istanbul (#11532) (Toru Nagashima)f16af43
Chore: fix formatters/table test (#11534) (Toru Nagashima)78358a8
Docs: fix duplicate punctuation in CLI docs (#11528) (Teddy Katz)The new version differs by 11 commits.
ded2f94
5.16.0
ea36e13
Build: changelog update for 5.16.0
dfef227
Build: gensite passes rulesMeta to formatter rendering (#11567)
c06d38c
Fix: Allow HTML formatter to handle no meta data (#11566)
87a5c03
Docs: func-style
: clarify when allowArrowFunctions
is used (#11548)
bc3e427
Update: pass rule meta to formatters RFC 10 (#11551)
b452f27
Chore: Update README to pull in reviewer data (#11506)
afe3d25
Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550)
4fe7eb7
Chore: use nyc instead of istanbul (#11532)
f16af43
Chore: fix formatters/table test (#11534)
78358a8
Docs: fix duplicate punctuation in CLI docs (#11528)
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.