Git Product home page Git Product logo

Comments (7)

Tratcher avatar Tratcher commented on August 24, 2024

You can't do new MemoryCache(new MemoryCacheOptions()); every time and expect it to contain the same data. You need to store the memory cache instance somewhere and re-use it between requests.

from caching.

Tratcher avatar Tratcher commented on August 24, 2024

Consider resolving IMemoryCache from DI

from caching.

zoinkydoink avatar zoinkydoink commented on August 24, 2024

apologies for my lack of understanding, If i have to store the memorycache instance then how does that make my access seamless? Maybe its due to my perception, I guess i was expecting it to work like System.Web.Caching.(currently using it for my mvc5 app)

I read somewhere that I may need to add services.AddCaching which gets me a copy of memorycache and distributedcache, is this still the case with the latest RC version?

in short, what I am trying to do is basically when my app starts, I want to store a collection into memory and be able to access this from any controller method.

What is the proper way to store a collection in cache and be able to use it from any controller within the mvc.

Also if you can point me to latest docs where I can read more on how this is suppose to work then maybe i will be better informed about this.

Thank you

from caching.

Tratcher avatar Tratcher commented on August 24, 2024

Even in System.Web you didn't create a new instance every time, you used the MemoryCache.Default instance. We've just moved it from the static Default to an injected service. You can find out more about injecting services over at https://github.com/aspnet/mvc

Yes, services.AddCaching is how to create the needed services.

The caching docs are still in progress. https://docs.asp.net/en/latest/fundamentals/caching.html

from caching.

davidfowl avatar davidfowl commented on August 24, 2024

You're not supposed to new anything up. You're supposed to use the instance provided by the DI container. Declare in your constructor that you need IMemoryCache and you will be handed one. Use that one

from caching.

muratg avatar muratg commented on August 24, 2024

@zoinkydoink Did using the instance provided by the DI work for you? Are you still having issues?

from caching.

muratg avatar muratg commented on August 24, 2024

Closing this as I haven't heard any problems using the instance passed by the DI. Please reopen or file another one if you're still experiencing issues.

from caching.

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.