Skip to content

A simple wrapper class that provides LRU caching to a simple data source such as a db query or a web service.

Notifications You must be signed in to change notification settings

dpan/CachingWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Caching Wrapper

A thread safe wrapper around a db or service call to provide "Least Recently Used" (LRU) Caching.

Usage

Initialize the wrapper. You can use any type for the key and the value.

In the following example a cache capacity of 100 is chosen. Use 0 to disable LRU caching.

var cachedSource = new CachingWrapper<int, string>(GetFromOriginalSource, 100);     

cachedSource.Retrieve(10); // Next time this key is requested, it'll be retrieved from the cache

Method used as a delegate to retrieve value from original source:

private string GetFromOriginalSource(int key)
{
    //  Retrieve value for the specific key from the database, a web service, a file or any other source
    return "result";
}

About

A simple wrapper class that provides LRU caching to a simple data source such as a db query or a web service.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages