maxpert / node-cache-manager-sqlite Goto Github PK
View Code? Open in Web Editor NEWA modern SQLite store for node-cache-manager
License: MIT License
A modern SQLite store for node-cache-manager
License: MIT License
This error is happend
const cacheCollectionSQLiteStore = cacheManager.caching({
store: sqliteStore,
options: {
serializer: 'json',
ttl: ONE_MINUTE * 60
}
});
async function getCollectionsInfoFromCache() {
const cacheStore = await cacheCollectionStore;
// Launch error
const dataCache = await cacheStore.get('foo');
}
Error image
Node 16.x
Strapi v4
cache-manager
v5 changed ttl from milliseconds to seconds.
So, if we works with cache-manager v5, we already use ms by default.
But here under the hood mset
multiply provided ttl by 1000.
node-cache-manager-sqlite/index.js
Line 171 in 36a1fe4
Suggestion: drop multiplying, add cache-manager v5+ to peer-deeps and increase major version of package.
upd: looks like cache-manager v5 changed a lot since v4, at least they not use callbacks anymore, so requires a bit more work for update current package.
Hi, huge fan of your library. I went ahead and forked it to meet the following needs:
cacheManager.caching
.Feel free to port/steal whatever you would like for this library! Open source!
In doing the porting, I noticed a bug in your implementation of mget
. The SELECT
statement for this is just an IN
query which will return unpredictably if keys do not exist OR the keys are not provided in alphabetical order. In practice, the following have issues from what I can tell:
await cache.set('a', 'a')
await cache.set('b', 'b')
await cache.set('z', 'z')
// This mget has a gap at position 'c' and it should return ['a', 'b', undefined, 'z'] but it returns ['a', 'b', 'z']
let [a, b, c, z] = await cache.mget('a', 'b', 'c', 'z')
// this will actually equal 'z'
assert(c === undefined)
// this is undefined as the array is only 3 elements long
assert(z === 'z')
// This mget returns items in reverse order and should be ['z', 'b', 'a'] but it returns ['a', 'b', 'z']
let [z, b, a] = await cache.mget('z', 'b', 'a')
// this will actually equal 'a'
assert(z === 'z')
// this will actually equal 'z'
assert(a === 'a')
The way I got around this is by using a varadic CTE that correctly orders and fills in the gaps in the query with almost equal complexity to an IN
statement you have.
> explain query plan WITH getKeys(key) AS (VALUES ("a"), ("b"), ("c"), ("z"))
SELECT
getKeys.key,
val,
created_at,
expire_at
FROM getKeys
LEFT JOIN kv ON kv.key = getKeys.key;
QUERY PLAN
|--CO-ROUTINE getKeys
| `--SCAN 3 CONSTANT ROWS
|--SCAN getKeys
`--SEARCH kv USING INDEX sqlite_autoindex_kv_1 (key=?) LEFT-JOIN
> explain query plan select * from kv where key in ("a", "b", "c", "z");
QUERY PLAN
`--SEARCH kv USING INDEX sqlite_autoindex_kv_1 (key=?)
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.