hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
2 stars 0 forks source link

Implement caching for entries. #132

Open hiyaryan opened 4 months ago

hiyaryan commented 4 months ago

Every time entries is loaded, calls to database are made. This happens every time the user navigates to the entries page. This can be reduced to one using caching.

The flow with caching:

  1. A user logs in and makes a request for their entries from the CDJ API.
  2. The CDJ API checks Redis if entries are cached: false.
  3. The CDJ API caches the entries in Redis for X time (this should be carefully considered based on the server storage, and potentially reset every time the user posts an entry as the data will become outdated)
  4. The user retrieves their entries.
  5. The user clicks away to visit another page.
  6. The user returns to their entries and makes another request to retrieve their entry data from the CDJ API.
  7. The CDJ API checks Redis if entries are cached: true.
  8. The CDJ API returns the cached entries.
  9. The user retrieves their entries data.

6 through 9 can be repeated every time until the user makes an action (e.g. posts a new entry) or the cache expires clearing the cache.