Why is the size of L1 cache smaller than that of the L2 cache in most of the processors?

L1 is very tightly coupled to the CPU core, and is accessed on every memory access (very frequent). Thus, it needs to return the data really fast (usually within on clock cycle). Latency and throughput (bandwidth) are both performance-critical for L1 data cache. (e.g. four cycle latency, and supporting two reads and one write by … Read more

How do I set expiration on CSS, JS and Images?

This is the one I use to fix the exact same thing when I ran the PageSpeed Addon: <FilesMatch “\.(jpg|jpeg|png|gif|swf)$”> Header set Cache-Control “max-age=604800, public” </FilesMatch> This goes into your .htaccess file. Read up on this page for more information about how to set cache for additional file types and/or change the cache length: http://www.askapache.com/htaccess/apache-speed-cache-control.html

How to invalidate cache data [OutputCache] from a Controller?

You could use the RemoveOutputCacheItem method. Here’s an example of how you could use it: public class HomeController : Controller { [OutputCache(Duration = 60, Location = OutputCacheLocation.Server)] public ActionResult Index() { return Content(DateTime.Now.ToLongTimeString()); } public ActionResult InvalidateCacheForIndexAction() { string path = Url.Action(“index”); Response.RemoveOutputCacheItem(path); return Content(“cache invalidated, you could now go back to the index action”); … Read more

Caching Data in Web API

The solution I ended up using involved MemoryCache in the System.Runtime.Caching namespace. Here is the code that ended up working for caching my collection: //If the data exists in cache, pull it from there, otherwise make a call to database to get the data ObjectCache cache = MemoryCache.Default; var peopleData = cache.Get(“PeopleData”) as List<People>; if … Read more

Should I use HttpRuntime.Cache?

HttpRuntime.Cache only provides severals methods and I think I’m able to implement these methods with Dictionary by myself. You think wrong. HttpRuntime.Cache is much more than a simple dictionary. It offers thread-safety and cache expiration policies. It provides possibilities of using custom implementation and benefit from distributed caching which is helpful in web farms. Implementing … Read more