kristofferahl/FluentSecurity — Issue #13: Caching of policy results
Author: kristofferahl
Created: 2012-01-25 18:25:24+00:00
State: open
Labels: feedback-needed

Started looking at different options for configuring caching in FluentSecurity v.2.0 and **I need some feedback** on what you think. None of the following syntax examples are in any way set in stone so please **feel free to suggest a better syntax**. The main thing I need feedback on though is **what options for caching you would prefer**. Please rank them in the order of importance (1-3).

**Option 1 - Caching per policy type:**

```C#
SecurityConfigurator.Configure(configuration =>
{
configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);

configuration.Advanced.CacheResultOf(Cache.PerHttpRequest);
configuration.Advanced.CacheResultOf(Cache.PerHttpSession);
configuration.Advanced.CacheResultOf(Cache.DontCache);

configuration.For().Ignore();

...
});
```

**Option 2 - Caching per controller action and policy type:**

```C#
SecurityConfigurator.Configure(configuration =>
{
configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);

configuration.For().DenyAnonymousAccess(Cache.PerHttpSession);
configuration.For(x => x.SomeAction()).DenyAnonymousAccess(Cache.PerHttpRequest);

configuration.For()
.ApplyPolicy(Cache.PerHttpSession)
.ApplyPolicy(Cache.PerHttpRequest);

...
});
```

**Option 3 - Caching per controller action:**

```C#
SecurityConfigurator.Configure(configuration =>
{
configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated);

configuration.For().CacheResults(Cache.PerHttpRequest).DenyAnonymousAccess();
configuration.For(x => x.SomeAction()).CacheResults(Cache.PerHttpSession).DenyAnonymousAccess();

...
});
```