A couple of MVC5 projects that takes a look at Caching using ObjectCache & MemoryCache. Also demonstrates partial views, AJAX and DI.
Developed with Visual Studio 2015 Community
###Techs
Tech |
---|
C# |
MVC5 |
AJAX |
jQuery |
Bootstrap |
StructureMap.MVC5 |
This project focuses on the 'OutputCache' attribute used to control caching on controller actions.
Feature |
---|
Caching data for a length of time using 'Duration' |
Specifying were data should be cached using 'System.Web.UI.OutputCacheLocation' |
Specifying cache profiles in web config. |
Project also demonstrates use of partial views and AJAX calls |
Navigate to the following urls and follow the instructions. The thing to watch out for is the 'Created' date.
Url | Description |
---|---|
http://localhost:[YourPortNumber]/Caching | Demonstrates caching data for a length of time using 'Duration' |
http://localhost:[YourPortNumber]/Caching/LongCacheProfile | Demonstrates caching data for a length of time using 'CacheProfile' |
http://localhost:[YourPortNumber]/Caching/ShortCacheProfile | Demonstrates caching data for a length of time using 'CacheProfile' |
http://localhost:[YourPortNumber]/Caching/CacheByParm | Demonstrates caching data by parameter |
http://localhost:[YourPortNumber]/Caching/AjaxCaching | Demonstrates caching data requested from an ajax call |
This projects contains a custom in-memory caching implementation using System.Runtime.MemoryCache.
Feature |
---|
Caching using System.Runtime.MemoryCache Here |
Adapter, Decorator patterns Here |
Light-weight Repository Pattern Here |
Dependency Injection with StructureMap Here |
AJAX calls Here |
Just run the 'MemoryCacheExample' project where you will be redirected to the 'Customer' view.
Filter the list of customers from the droplist provided.
Observe the 'access date' for each customer, you will notice that it only changes after 1 minute.
###Resources
Title | Author | Website |
---|---|---|
ASP.NET Caching | MSDN | |
ASP.NET Caching: Techniques and Best Practices | MSDN | |
Caching infrastructure in MVC4 with C# | Andras Nemes | dotnetcodr |