RealWorldCoder
RealWorldCoder

Reputation: 1021

How to use a non-default instance of ObjectCache?

I set-up the object:

ObjectCache MyCache = new MemoryCache("MyCache");

Trying to use that instance in the future, and I tried this:

ObjectCache MyCache = MemoryCache("MyCache");

But gives an error.

I figured it works, because this code works:

ObjectCache DefaultCache = MemoryCache.Default;

But only lets me use the default cache. I'm not sure how to use the MyCache instance I created in the future. How do I do this?

Upvotes: 0

Views: 349

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Once you have created this MyCache variable instance you could store it as a static property to some class or configure it in your DI framework so that it gets automatically injected to all classes taking an ObjectCache constructor dependency.

Upvotes: 3

Related Questions