A thread-safe caching abstraction for .NET -- leverages object cache, filesystem and Azure Blob Storage (Amazon S3 coming soon). Johnny Cache was designed to improve application performance in both single-server and web-farm systems.
There are 3 primary configuration variables that need to be set in your App.Config/Web.Config
<!-- JOHNNY CACHE -->
<add key="JC-ObjectCacheName" value="JohnnyCache-SomeProject"/>
<add key="JC-WorkingDirectory" value="c:\temp\JohnnyCache\SomeProject"/>
<add key="JC-ExpirationInSeconds" value="300"/>
Note: None of the above configuration variables are required, as they all are backed by default return values;
To leverage Azure Blob Storage add the following keys to your App.Config/Web.Config
<add key="JC-AzureAccountName" value="{{YOUR ACCOUNT NAME}}"/>
<add key="JC-AzureAccountKey" value="{{YOUR ACCOUNT KEY}}"/>
throw new NotImplementedException("Coming Soon!");
The API for Johnny Cache is very simple, containing only 3 methods: Get()
Set()
Delete()
.
The Get()
method will:
- Check Object Cache
- Check the File Dependancy
- Check External Providers (if configured, see above)
The primary method parameter here is the key
. For "stale" checks you can optionally pass a cacheDurationSeconds
param to override the library-governing expiration.
string cacheKey = "SomeUniqueCacheKey";
YourCoolObject mycoolObject = JohnnyCache.CacheIO.Get<YourCoolObject>(cacheKey) as YourCoolObject; //using library expiration
YourCoolObject mycoolObject = JohnnyCache.CacheIO.Get<YourCoolObject>(cacheKey, 6000) as YourCoolObject; //overriding library expiration
The Set()
method will:
- Write to Object Cache
- Write to the File Dependancy
- Upload to External Providers (if configured, see above)
The primary method parameter here is the key
. For "stale" checks you can optionally pass a cacheDurationSeconds
param to override the library-governing expiration.
string cacheKey = "SomeUniqueCacheKey";
JohnnyCache.CacheIO.Set(myCoolObject, cacheKey); //using library expiration
JohnnyCache.CacheIO.Set(myCoolObject, cacheKey, 6000); //overriding library expiration
The delete method will purge the object(s) from all levels of cache.
The lone method parameter here is the key
.
string cacheKey = "SomeUniqueCacheKey";
JohnnyCache.CacheIO.Set(cacheKey);