Git Product home page Git Product logo

Comments (3)

jodydonetti avatar jodydonetti commented on May 20, 2024

Hi @hvgNET and thanks for considering FusionCache.

Sorry for the delay in answering but covid finally got me.

In general your idea seems the right one to me:

  • load all 10.000.000 items from the db in one go
  • save them all in the cache individually with a Set call for each of them (with a reasonable cache duration)

Then, when you need one of them during the lifetime of your application, call GetOrSet({id}, _ => GetValue(id)) so that if the value is still in the cache you'll get it back immediately and, if not in the cache anymore, it will be loaded from the db and saved in the cache.

There's this passage that I don't understand though:

But that just seems... a bit hacky to me as i neither want to get nor set the value, i just want to set the factory up

Why do you say it feels hacky? Just to be clear, you don't need to call GetOrSet for each item when you are prefetching the entire thing at the beginning, you only need to call GetOrSet later on when you need some of those values and, in that moment, the GetOrSet means "get me X from the cache and, if it is not there, load it and set it".

Maybe you are thinking about calling GetOrSet for each key in the initial prefetching phase? If that is the case, that is not necessary.

So, to recap:

  • INITIAL PREFETCHING: load all items from db -> for each item call Set with a reasonable duration
  • DURING YOUR NORMAL APP USAGE: call GetOrSet so that if the value is expired from the cache it will be loaded again

Doing it this way will allow you to have the cache already filled at start + automatically keep some of those items in the cache, based on actual usage.

Let me know if I got this right and if I can help you more.

Hope this helps.

from fusioncache.

jodydonetti avatar jodydonetti commented on May 20, 2024

ps: if you plan on also using a 2nd layer (distributed cache) keep in mind that the initial prefetching may not be necessary, since the data may already be in the distributed cache because of previous runs.

from fusioncache.

jodydonetti avatar jodydonetti commented on May 20, 2024

I'm converting this into a discussion.

from fusioncache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.