Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache static class's Data in Silverlight

I have static class that holds some info

public static class SampleDataCache
{
    private static Dictionary<string,SampleData> cacheDict = new Dictionary<string,object>()

    public static Get(string key)
    {
        if(!cacheDict.Contains[key])
            cacheDict.Add(key,new SampleData());

        return cacheDict[key];
    }
}

And when I refresh page I want SampleDataCache to keep its data.

Can I achieve this in simple way?

like image 252
Stecya Avatar asked Feb 16 '11 15:02

Stecya


1 Answers

Since the cache, in its current form, is stored in memory then the data is naturally cast into oblivion when the page refreshes - that's a new instance of the application starting there. You might, however, be interested in utilising isolated storage in order to persist data per-user.

With isolated storage you essentially have a contained file system into which you can store data and then further retrieve it. One step in the right direction could be to make a class you want to represent a 'piece' of cached data, make it serializable, then using your static class as the cache controller you can read and write these objects from and to isolated storage.

Quickstart: Isolated Storage in Silverlight

like image 64
Grant Thomas Avatar answered Oct 23 '22 19:10

Grant Thomas