Add the global redis cache the ability for caching query results
New Issue Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest version of Parse Server.
Issue Description
It would be nice to have global redis cache cache query results from Mongo DB by default.
Steps to reproduce
- Install a redis server and make sure it's running.
- Connect the redis server to parse via redis adapter like this:
const RedisCacheAdapter = require("parse-server").RedisCacheAdapter;
const serverConfig = {
...
cacheAdapter: new RedisCacheAdapter({ url: process.env.REDIS_URL }),
...
}
Environment
node 18.2.0 redis-server on local docker v7.0.10 redis-server on digital ocean droplet with ubuntu 22 v7.0.4
Server
- Parse Server version:
^6.0.0 - Operating system:
Win 64 - Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
Redis server tested both on redis-server version=7.0.10 on a local docker container as well as digital ocean droplet with ubuntu 22 redis-version 7.0.4
Database
- System (MongoDB or Postgres):
Mongo - Database version:
5.0.15 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
Atlas
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
JavaScript - SDK version:
^4.0.1
Logs
Thanks for opening this issue!
- 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
This sounds more like you're looking for support on how to set up Redis cache with Parse Server.
- For help with Parse Platform we recommend our community forum or our community chat
- For general coding questions we recommend Stack Overflow using the parse-platform tag
- For network and server questions we recommend ServerFault using the parse-server tag
Thank you for these resources I will check them out.
But there's not really any setup necessary, just copy and paste 2 lines of code which I did.
And my redis servers are up and running.
So this might be a bug rather than just me asking for support.
Thank you.
Thanks for providing more details, if you can confirm that this is a bug and not an issue with your custom setup then please post here and we'll reopen the issue.
From my observation, Parse Server uses an inbuilt cache / redis cache to store User Roles and User Data to speed up the time it takes to resolve a cloud request (beforeFind, afterFind, etc). It does not provide a "global cache" that stores query responses.
If you use a Redis GUI such as RedisInsight you can observe this happening.
Thanks for confirming my surmise.
Yes, so I think you would need to reword this as a feature request rather than a bug because the cache is working as expected.
See: https://docs.parseplatform.org/parse-server/guide/#configuring-cache-adapters
By default, parse-server provides an internal cache layer to speed up schema verifications, user, roles and sessions lookup.
In some cases, in distributed environment, you may want to use a distributed cache like Redis.
I think this is a duplicate of #4750.
I think it would be hard to decide how a global cache should work, if it's providing a short-circuited response from beforeFind and afterFind triggers. A developer might have custom logic that they want to run in a trigger, regardless of whether the response is cached or not.
It seems like Flo's suggestion was:
- Allow beforeFind triggers to return objects
- This could allow for custom query returns, for example if a developer is using a custom search such as ElasticSearch
- This could allow cached objects to be returned
- Pass objects in
afterFindto a cache adapter
It's worth noting that whether or not a cacheAdapter is specified, Parse Server will cache schema verifications, user, roles and sessions lookup in an in-memory cache. If we introduce the ability to cache query responses, we will need to make sure that the default behaviour is considered.
We could possibly add a parameter to SCHEMA or Cloud Validators of cache: true which interprets whether to cache query results with the CacheAdapters ttl
Just as we were speaking there was a package out that does query result caching:
https://community.parseplatform.org/t/parse-cache-memory-a-cache-library-customized-for-parse-server-queries/3367/5
I've tested it and my query responses improved from 200ms to 1ms.