asp.net - MemoryCache.Default invalidated after first Request -


i have weirdest problem - started using memorycache , thought pretty straightforward... turns out isn't. empty asp.net mvc5 application, hosted on local iis 7.5

on first request value should have been added cache - if refresh page, cache should hold value.

when debug application, breakpoint (on commented line) gets hit twice: on first request, on second request. after cached value can used.

why cache not return value on first reload expected?

public class temp {     public int age { get; set; } }  public class homecontroller : controller {     public actionresult index()     {         var temp = (temp)memorycache.default.get("myval");          if (temp == null)         {             // gets hit on first 2 requests, after cache returns value             temp = new temp { age = -127 };             memorycache.default.add("myval", temp, datetime.utcnow.addminutes(10));         }           return view();     } } 

i not think need use memorycache in mvc app. requires bit of custom implementation working. why not use httpcontext.cache instead? extremely simple use , can configured liking - there lot of tutorials on web. (i made small tutorial while ago, can check out if have trouble starting)


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -