Invalidate Redis Cache

Hi.
How to invalidate a particular cached item stored in Redis?
It could be anything - sockets, content page, SA etc - whatever is cacheable.

I read these two posts regarding it: Redis cache confusion & Redis cache upgrades but could not make sense of it much.

Please help.

Redis is a key-value store, meaning you do stuff like:

SET something 123
GET something // will return "123"
  1. Find all references of “redis” on your app’s source-code:
# Linux/MacOS only, or Windows with GNU tools installed or Git shell
grep redis * -r | grep -v node_modules
  1. You discover Wappler’s using this package:
    https://www.npmjs.com/package/express-redis-cache
  2. You find the relevant information:
    https://www.npmjs.com/package/express-redis-cache#name-of-the-cache-entry

You can use the command DEL to erase a specific key. Be careful about listing all existing keys, it could hang your Redis for a while

Redis commands are to be typed on redis-cli

If you don’t care about existing cache you can use “FLUSHDB” to erase all keys

So I’ll have to create a custom extension to get this done?
No Wappler-way to do it?

Oh, so is this not a one-time thing (to erase the cache)?

Well, I guess in that case you would need a custom extension indeed. You can maybe glance over posts by JonL mentioning “Redis” in the Wappler Extensions category

The logic for del and other redis commands is already implemented in lib/modules/redis.js.

You just need create the hjson and a js file that imports the needed function(s).

I had the same issue, so I ended up creating a custom caching module. The module takes a unique prefix that is added to every item stored in the cache. This means any operation related to this module can be scoped, so I can remove a specific key or clear the cache and it only affects the items with the prefix and prevents it form affecting the other Wappler scripts using the redis instance.

The other benefit is that you can cache specific actions and values as opposed to caching the entire request, which means server side scripts also get a performance boost if they use those actions as well.

If you’re using nodeJS, I would recommend this library.

I always forget to look in the Wappler libs. I did find the relevant code.
Should be easy to configure the custom extension from here. Thanks. :slight_smile:

That looks interesting. For now, I think I will just use the Wappler’s Redis setup.
With the various Redis functions available in Wappler itself, I think I can also save custom data.