All Projects → adamgordonbell → attribute-based-caching

adamgordonbell / attribute-based-caching

Licence: other
Cache expensive methods calls with a declarative attribute. No custom code required. Configure caching method.

Programming Languages

C#
18002 projects
smalltalk
420 projects

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

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].