dimanche 3 juillet 2022

What is the correct way to cache and enrich a specific search result?

I have a code that has 2 APIs for the user:

  1. Search API - returns 'shallow movies' results that each one has only few fields (e.g. id, title, subtitle and icon image).

  2. Drill down a specific result - The user sends an id of one of the results he got in the "Search API", then the program will fetch many more data about this result (from DB and other sources) and return 'detailed movies' result that includes both the data from the shallow model and the new data.

Because I don't want to fetch all the shallow result data again I am saving all the shallow results in cache and then in the drill down API, I fetch from cache and find the result that matched the id the user sent.

On the shallow result model, I have many fields (except what I wrote above) that shouldn't be returned in any of the API's and are used only for logs and some other uses. My problem is that I'm not sure what is the best way to model the shallow result model. I thought I can have the following Movie class that contains 2 inner classes:

  • Movie
    • MovieCache
    • MovieExtraData (all the fields that shouldn't be saved to cache)

It feels a little weird to me because in this way the Movie model becomes very specific to this flow and I may use it in many other flows too.

Sorry for the length, any suggestions? Thanks!

Aucun commentaire:

Enregistrer un commentaire