问题
I have a few large objects which need to be stored and fetched from cache. These objects are around 1 - 2 mb in size.
When running with localCache
enabled, retrieval takes no more than a few milliseconds, but without it, it takes around 3 seconds, consistently.
I am using Azure In-role cache (colocated).
Can anyone shed some light as to why it would be so much slower without localCache enabled?
回答1:
LocalCache is local to the process, i.e. within the application's process memory. If LocalCache is enabled, object fetched from cache will also be stored in LocalCache. Every next request for that object will be served from that LocalCache (No need to fetch from out of process cache). However retrieving object for the first time will take time.
According to MSDN:
When local cache is enabled, the cache client stores a reference to the object locally. This keeps the object active in the memory of the client application. When the application requests the object, the cache client first checks whether the object resides in the local cache. If so, the reference to the object is returned immediately without contacting the server. If it does not exist, the object is retrieved from the server. The cache client then deserializes the object and stores the reference to this newly retrieved object in the local cache. The client application uses this same object.
Whereas when local cache is disabled, every retrieval request is directed to out-proc cache, resulting in fetching object from outside process's memory every time.
-Sameer
来源:https://stackoverflow.com/questions/26439540/caching-large-objects-localcache-performance