Giter Club home page Giter Club logo

node-cache-manager-sqlite's People

Contributors

maxpert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-cache-manager-sqlite's Issues

[Bug] store.get is not a function

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

image

Node 16.x
Strapi v4

[Bug] `.set` and `.mset` works not correctly with cache-manager v5

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.

const ttl = (options.ttl || this.#default_ttl) * 1000

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.

mget does not return the correct number of returns if values are undefined or the keys are not in alphabetical order

Hi, huge fan of your library. I went ahead and forked it to meet the following needs:

  • Make it work with cache-manager@5, which simplified the storage contract to be less variadic and more predictable. This doesn't appear to be backwards compatible.
  • Converted it to Typescript so that I can get code completion when passing it to cacheManager.caching.
  • Swapped in better-sqlite3 for sqlite3 as the former is "faster" and the latter uses a node-gyp fork that has bunch of testing required into code that is shipped with the library which breaks builds in an Astro / Vite setup that I'm working in.

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=?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.