PostSharp Caching

The straightforward way to improve your application performance.

  • Improve application performance without adding repetitive code.
  • Reduce cache key generation bugs.
  • Support for MemoryCache, Redis, Pub/Sub, and more.
  • Customizable. Plug in your own cache storage.

PostSharp Essentials

FREE

10 enhanced classes per project.

PostSharp Ultimate

$695 per developer

No limitation whatsoever.

Declarative caching and invalidation

[CacheConfiguration( AbsoluteExpiration = 10 )]
class CustomerServices
{
    [Cache]
    public static Customer GetCustomer(int id)
    {
       return DetailsSkipped();
    }

    [InvalidateCache(nameof(GetCustomer))]
    public static void RenameCustomer(int id, string newName)
    {
        // Parameter 'id' of 'GetCustomer' method matched by name.
        DetailsSkipped();
    }
}
  • Add caching to a method with a simple custom attribute.
  • Cache key automatically generated based on method name and parameter values.
  • Invalidate cached method with custom attribute and automatic, build-time parameter matching.
  • Fully customizable.

Object-oriented invalidation

  internal class AccountServices
  {
    [Cache]
    public static Account GetAccount(int id)
    {
      // Add an object-oriented dependency to GetMethod.
      CachingServices.CurrentContext.AddDependency(new AccountDependency(id));
      return DetailsSkipped();
    }

    [Cache]
    public static Account[] GetAccountsOfCustomer(int customerId)
    {
      // Implicitly adds dependencies to Account(1) and Account(2).
      return GetAccountIds(customerId).Select(GetAccount).ToArray();
    }

    public static void UpdateAccount(Account account)
    {
      // Invalidates both GetAccount and GetAccountsOfCustomers.
      CachingServices.Invalidation.Invalidate( 
                                           new AccountDependency(account.Id));
    }
}
  • Improve seperation of concerns between readers and updaters.
  • Dependencies of called methods automatically added to the caller context.
Break free from routine TODAY and start delivering more in less time.