0

Let's say I want to store the user's First and Last name in the client-side cache (browser) which will be fetched throughout the site. This will then expire after some time. How can I do this using ASP.NET MVC (i.e. storing and fetching data in the cache through the controller)?

I tried using HttpContext.Current.Cache but that apparently uses server-side caching. So what happened was when users logged in at the same time, they were getting a different first and last name.

Thanks!

  • Possible duplicate of [ASP.NET MVC - caching pages on client side](https://stackoverflow.com/questions/14609291/asp-net-mvc-caching-pages-on-client-side) –  Feb 09 '18 at 05:10
  • 1
    Hi Amy. I'm trying to store and fetch pieces of data (e.g. first and last name) in the cache instead of an entire page. How can this be done using OutputCache? – Adrian Valenzuela Feb 09 '18 at 05:15
  • If it's small information then, Why don't you go for cookie or else session ? – Ray Feb 09 '18 at 05:30
  • 2
    @AdrianValenzuela its the same thing. just replace the word "page" with "data". its treated the same way. `OutputCache` caches the *result* of the action method. If the result is a page, it caches a page. If the result is data, well, guess what happens. –  Feb 09 '18 at 05:46
  • Use javascript `localStorage` method `setItem()` and `getItem()` but it will not automatically expire after some time. – sridharnetha Feb 09 '18 at 07:14

0 Answers0