tags:

views:

79

answers:

3

I'm looking for some convenient way to cache data on disk. Basically a key-value store with expiration and the value being (xml)serialized .

Something that could be used like...


var userCacheId = "3332";
var userData = cache.Retrieve(
    userCacheId,
    () => readUserDataFromDatabase(userCacheId), // Load delegate if not in cache
    TimeSpan.FromMinutes(30)); // expiration time

It should be - Used on a Windows Application - Automatically clean up expired cache entries / free the used disk space - Be thread safe - Allow to remove cache entries by key

Any suggestions on this? Maybe some hip NoSql Database would do exactly that? :)

A: 

How about System.Runtime.Caching?

Stephen Cleary
A: 

Most caches are memory caches (as caching a database result to disk really wouldn't buy a whole lot as far as retrieval goes unless your database is a serious bottleneck). If you want the cache to be local, System.Runtime.Caching should take care of your needs. If you want the cache to be highly-available and updatable across nodes, I suggest looking into NCache or memcached.

Jesse C. Slicer
As far as i can see, System.Runtime.Caching provides only in-memory-caching and an interface someone *could* use to implement a persistent one.Basically i wan't to take work from the data source by caching it but i don't want it to waste up precious memory. e.G. i display rss feeds and i don't intend to read from the server more than once an hour, no matter how often the displaying form is opened or whether my application is restarted.I'm going to take a look at your links... can't be i'm the first person wanting a simple cache outside the web-app-world :)
Daniel K.
Daniel K - I'm in the same boat: I have some moderately expensive operations that I would like to cache to disk instead of redoing them - in my case these are batch operations on images, not db calls.
Oskar Austegard
A: 

Found this: http://www.eggheadcafe.com/tutorials/aspnet/56161e9e-7fa3-48e8-9dfe-9f7a28f4d58e/filebased-cache-for-web.aspx File-Based Cache for Web and non-Web Apps plus Extend ASP.NET 4.0 OutputCacheProvider By Peter Bromberg

from http://stackoverflow.com/questions/3396328/disk-based-cache-using-providerbase

Oskar Austegard