Last post Oct 20, 2017 03:14 AM by Deepak Panchal
Oct 19, 2017 08:07 PM|Sakkaku|LINK
I want to use System.Runtime.Caching.MemoryCache. But if I import it and use MemoryCache, there is a namespace called MemoryCache and I cannot get the class MemoryCache.
I can get the class with System.Runtime.Caching.MemoryCache, but writing that everytime is not how it should be done. And is very annoying. Why can't I get the Class? And where is the Namespace coming from?
Oct 20, 2017 03:14 AM|Deepak Panchal|LINK
did you try to assign it to object when you include the namespace?
you can try to use like it and then every time you not need to write whole namespace. instead of that you can just use "nmspce" (it is just object name that I use here. you can name it whatever you like.)
below is one example for System.Runtime.Caching.MemoryCache.
private void btnGet_Click(object sender, EventArgs e)
ObjectCache cache = MemoryCache.Default;
string fileContents = cache["filecontents"] as string;
if (fileContents == null)
CacheItemPolicy policy = new CacheItemPolicy();
List<string> filePaths = new List<string>();
// Fetch the file contents.
cache.Set("filecontents", fileContents, policy);
Label1.Text = fileContents;
How to: Cache Objects Simply using System.Runtime.Caching.MemoryCache
Using MemoryCache in .NET 4.0
Working with System.Runtime.Caching.MemoryCache