Skip to main content

Posts

Showing posts with the label Caching

Affects of caching on UI service layer

In a previous post I talked about the how the use of an ORM would have saved development time. Having made the statement I thought I would share how the UI service layer we introduced still received a considerable benefit from the introduction of an in-memory cache. The constructor for the service is shown below, as you can see pretty standard really, the interesting interface is the ICacheProvider. As I said in the previous post this service interface and implementation would not exist if an ORM had been used. The ICacheProvider interface is literally an abstraction around the  MemoryCache  provided by .Net framework, this then allowed a null caching provider to be defined as well as testing isolation. public interface ICacheProvider { bool Add ( CacheItem item , CacheItemPolicy policy ) ; object AddOrGetExisting ( string key , object value , CacheItemPolicy policy , string regionName ) ; bool Add ( string key , object valu...

Considerations when building a caching mechanism for WP7Contrib.

For anyone wanting to build a cache for an application, there are several guidelines(may be rules) you want to beware of and more than likely abid by. Firstly, more than likely you are going to have an in-memory representation of the cache as well as a persisted format if the cache is to survive application restarts. Now an in-memory representation is more than likely going to be a hash-table - especially if you want acceptable retrieval time. Now this is where 'GetHashCode' comes into play and the importance of this is explained perfectly by Eric Lippert , Secondly, and this follows on from a statement in Eric's post - 'the integer returned by GetHashCode should never change', if you're using the internal state of a class to calculate the hash code, you can't allow that state to change overtime. So this means you are more than likely going to have create a copy of the instance before using it as a 'key' when adding to the cache, because this wil...

WP7Contrib: Isolated Storage Cache Provider

15/04/2001 - The code for this example has been updated - new WP7 build of SilverlightSerializer, this has removed the explicit implementation of ISerializeObject interface from the example model classes. WP7Contrib received it's first question on the discussions forum, it was about how to use the  IsolatedStorageCacheProvider . Rich & I have been using this for a while in development and the question highlighted the lack of examples on how to use some of the stuff we've pushed out. So I thought I would share some insight into the demo I produced to answer the question. You'll find the demo in the 'CacheProviderDemo' in the 'Spikes' directory in the  code-base . It demostrates how to add both value & reference types to the cache, how these gets persisted to isolated storage and how values are purged from the cache. Before I show some code snippets I'll give some background to our thinking about caching. As wikipedia states 'a cache...