c# - How to cache data in memory in a mvc 4 application -


i trying implement caching in mvc 4 application. want retrieve data once , not have go database , forth. followed url below. code runs caching not happening

http://stevescodingblog.co.uk/net4-caching-with-mvc/

if set break point on method below never returns data cache. going new data i.e vehicledata null.

i new caching. best way implement memory caching? using mvc 4 , visual studio 2013. cache.set outdated?

      public ienumerable<vehicle> getvehicles()             {                 // first, check cache                 ienumerable<vehicle> vehicledata = cache.get("vehicles") ienumerable<vehicle>;                  // if it's not in cache, need read repository                 if (vehicledata == null)                 {                     // repository data                     //vehicledata = datacontext.vehicles.orderby(v =&gt; v.name).tolist();                      vehicledata = datacontext.vehicles.orderby(g=>g.name).tolist();                      if (vehicledata != null)                     {                         // put data cache 30 minutes                         cache.set("vehicles", vehicledata, 30);                      }                 }                  return vehicledata;             } 

reference system.web dll in model , use system.web.caching.cache

public string[] getnames() {   string[] names = null;   if(cache["names"] == null)   {     names = db.getnames();     cache["names"] = names;   }   else   {     names = cache["names"];   }   return names; } 

http://www.dotnet-tricks.com/tutorial/mvc/4r5c050113-understanding-caching-in-asp.net-mvc-with-example.html

http://www.codeproject.com/articles/757201/a-beginners-tutorial-for-understanding-and-imple


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -