Giter Site home page Giter Site logo

adonis5-cache's People

Contributors

mastermunj avatar reg2005 avatar vladyslavparashchenko 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

Watchers

 avatar  avatar  avatar

adonis5-cache's Issues

Flushing cache with tags only removes tags record

Flushing with tags only causes the tag record to be removed. The actual records are not removed.

Before Flush After Flush
image image

The expiration time is not being set correctly.

If I add to the cache at 2024-02-14 00:16:47 and the record will expire in one hour, the expiration time in the tag is 2024-02-14 00:16:47, not 2024-02-14 01:16:47

{
  "expirationTime": "2024-02-14T00:16:47.308Z",
  "keys": [
    "programmes:{\"filter\":{\"epgId\":\"abc.us\",\"startAt\":\"2024-02-14T00:00:00.000+00:00\"}}"
  ]
}

My cache config is this

import { CacheConfig } from '@ioc:Adonis/Addons/Adonis5-Cache';

export default {
  recordTTL: 60, // record ttl in minutes,

  ttlUnits: 'm', // time units for ttl record

  currentCacheStorage: 'redis', // storages which used as default cache storage

  enabledCacheStorages: ['in-memory', 'redis'], // storages which will be loaded

  cacheKeyPrefix: 'cache_record_', // prefix for keys, which will be stored in cache storage

  enabledEvents: {
    'cache-record:read': false,
    'cache-record:written': false,
    'cache-record:missed': false,
    'cache-record:forgotten': false,
  },
} as CacheConfig;

This is getting the TTL as 60, instead of it being converted to ms, so it's only adding 60ms to the expiraton instead of 3600000ms.

protected async saveTaggedKeys(keys: string[], ttl: number = this.cacheManager.recordTTL) {
const tagPayload = JSON.stringify({
expirationTime: dayjs().add(ttl, 'ms').toISOString(),
keys,
})
await Promise.all(
this._tags.map((tag) => this.storage.addTag(this.buildTagKey(tag), tagPayload))
)
}

Changing this to

protected async saveTaggedKeys(keys: string[], ttl: number = this.cacheManager.recordTTL) {
	const tagPayload = JSON.stringify({
		expirationTime: dayjs().add(ttl, this.cacheManager.cacheConfig.ttlUnits).toISOString(),
		keys,
	})
	await Promise.all(
		this._tags.map((tag) => this.storage.addTag(this.buildTagKey(tag), tagPayload))
	)
}

Fixes the issue.

Package version

1.3.1

Node.js and npm version

v18.17.0

Sample Code (to reproduce the issue)

await Cache.tags('programmes').put(cacheKey, programmes);

await Cache.tags('programmes').flush()

New adonis redis version

Hey,

Could you please update the adonis redis version. The current one 7.0.2.

At the moment if someone uses the auth module this package can't be installed because of this issue.

The auth module needs the 7th version of redis, you need the 5th.

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.