1. What is this?
Cache expensive methods calls with a declarative attribute. No custom code required.
2. Simple Example
[Cache.Cacheable] //this method now cached, will only be called once per guid
public SomeExpensiveObject GetExpensiveObject(Guid userId)
{
..
}
3. Cache with invalidation:
[Cache.Cacheable("UniqueKeyForThisMethod")] //cache using this key plus parameter(s)
public SomeObject GetObjectById(Int32 Id)
{
...
}
[Cache.TriggerInvalidation("UniqueKeyForThisMethod")] //delete from cache using this key and passed parameter(s)
public void RemoveObjectById(Int32 Id)
{
..
}
More examples can also be found here: http://cascadeofinsights.com/post/1410736927/introducing-attribute-based-caching
4. How does it work
Using postsharp to make method interceptions when a cached version exists
4.1 Configuration
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="aopCacheConfiguration" type="CacheAspect.Config.AopCacheConfiguration, CacheAspect" />
</configSections>
<aopCacheConfiguration type="CacheAspect.MemoryCache" path="" ttl="7:0:0:0" />
<system.runtime.caching>
<memoryCache>
<namedCaches>
<clear />
<add name="PostSharp.Cache" cacheMemoryLimitMegabytes="256" pollingInterval="00:05:00" />
</namedCaches>
</memoryCache>
</system.runtime.caching>
</configuration>
5. More / Press / Blogs
- http://paulstack.co.uk/blog/post/Attribute-Based-Caching-with-PostSharp.aspx
- http://cascadeofinsights.com/post/1410736927/introducing-attribute-based-caching
- http://www.infoq.com/news/2011/04/Attribute-Caching
- http://www.postsharp.net/blog/post/Attribute-Based-Caching-and-Unit-Testing-of-Aspects
- http://stackoverflow.com/questions/5328819/caching-attribute-for-method
6. Previous Releases (on codeplex)
1.00
- Original Codeplex Release
1.2
- faster key generation strategy - thanks payman
- basic unit tests - thanks payman
- btree disk cache
- removed unity dependency
- simple timetolive setting
1.2.1
- adding ignoreTTL
- adding support for colection to KeyBuilder
- adding deconstructor to btreecache - to clean up open filestream
- add compile-time reflection cache attribute
- GitHub version is the most recent version
1.2.2
- adding app.config based configuration