Is there a better way to implement a server-side cache for Silverlight?

Is there a better way to implement a server-side cache for Silverlight?

Old forum URL: forums.lhotka.net/forums/t/11284.aspx


RobKraft posted on Friday, April 06, 2012

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;
}
}

JonnyBee replied on Friday, April 06, 2012

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 

RobKraft replied on Monday, April 09, 2012

Thanks for the suggestion, I will look into that.

TSF replied on Monday, September 24, 2012

Are there any examples showing how to use the caching feature in CslaContrib?

RockfordLhotka replied on Monday, September 24, 2012

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