I am in the middle of building out some wcf endpoints to support the Dimecasts.net WP7 application I am going to publish. The code below is some of my main logic which helps grab the episodes. Because the data for Dimecasts is not very volatile I am going to do some basic (aka primitive) caching.
What I am looking to do is save the amount of data which needs to be gathered from the db. The intent of the code below is to get all data from cache which is greater then the last known episode which is cached on the phone. If data is found in the cache we will adjust the ‘last known episode’ in order to again reduce the db hit. However, there is a slight bug.
Who can spot the bug?
public IList<EpisodeModel> FetchEpisodes( Int32 lastKnownEpisodeId )
{
var episodes = new List();
var cachedEpisodes = Cache.FetchEpisodes()
.Where( x => x.EpisodeNumber > lastKnownEpisodeId )
.OrderBy( x => x.Id );
if ( cachedEpisodes.Count() != 0 )
{
// reset the last known id in order to reset the reset
lastKnownEpisodeId = cachedEpisodes.LastOrDefault().Id;
episodes.AddRange( cachedEpisodes );
}
// more code which does not matter here.....
return episodes;
}
If you know the issue post it in the comments. If it is not ‘solved’ I will post an update with the solution and the reason.
Till next time,
Posted
01-21-2011 5:10 PM
by
Derik Whittaker