I’m working on web app using nestJs/postgres/redis.
What is the best way (best data structure) to cache following postgres table (hierarchy) to Redis ?
space:
- name
- another attribute
- users (one2many)
folders:
- spaceId
- name
- users (one2many)
files:
- folderId
- spaceId
- name
- users (one2many).
I already tried to cache this using key-value where the key is hashed from request and value is response of say getAllMyFiles but there will be some problem
Say i want to cache The route:
/my-files
key: users:[USER_ID]:documents:[QUERY-HASH]
the problem is that:
- i have to cache this for every user and thus the cache will get bigger
- when updating one file i have to invalidate the entire files-cache for all the users
2
Answers
I think that the best solution is to use Redis graph
Could this be a good candidate for RedisJSON? You could store the space and all its hierarchy as a single JSON document.