We want to cache data server side so that we don't need to make the database calls for every silverlight client. Our objects are also used by Asp.Net web apps and desktop apps. Ideally, I'd like to set the value of this to the collection that was cached, but that is not possible.
The only alternative we have come up with is to loop through the items in the cache calling this.Add. That is probably better than a database call, but feels less efficient than "this = cache".
Is there a way to implement something like this below?
private void DataPortal_Fetch(CriteriaHash criteria)
{
if (_cache != nulll)
{ this = _cache;
}
else
{_cache = GetData()//GetData adds to this;
}
}
You may look into CslaContrib and the serverside caching with AppFabric. or plain InMemoryCache.
Uses a custom CacheDataPortal (serverside DataPortal) and ObjectCacheAttribute and ObjectCacheEvictionAttribute at classlevel to determin if object is Cachable and when to evictfrom cache. All that is required is configuring to use the custom DataPortal and add attribute to the actual classes.
CacheAttribute is configurable for CacheScope (Global,Group,User).
Http://CslaContrib.codeplex.com
Thanks for the suggestion, I will look into that.
Are there any examples showing how to use the caching feature in CslaContrib?
You should also look at the ObjectFactory data portal concepts (factory encapsulation), because in an object factory you really _can_ just deserialize a copy of the object out of the cache and return it as the result.
public MyClass Fetch(CriteriaHash criteria)
{
MyClass obj = null;
// get object from cache, or from database
MarkOld(obj);
return obj;
}
Copyright (c) Marimer LLC