Table of Contents

Cache

Description

Application-level in-memory cache with built-in sharding for thread safety and scalability.

Features

  • Sharded cache: 8 cache containers out of the box
  • Auto-generated key: includes namespace, class, method name, IsAuthenticated, user roles, and scoped variables of type string, int, DateTime, bool, or enum

Behavior

  • Duration: 3 minutes default
  • CacheDuration: Predefined enum or any integer (seconds)
  • Capacity: 320,000 items across 8 shards (40,000 per shard, configurable)
  • Eviction: When full, 33% of items are removed via IMemoryCache eviction policy
  • Fallback [Pro Tier]: Serves previously cached data when getItem() returns null or throws, for up to 3 minutes after primary expiration
  • Skip Options
    • skipWhenAuthenticated: Defaults to false
    • skipWhenAdmin: Defaults to true, matches roles: Admin, Admins, Administrator, Administrators, WebAdmins, CmsAdmins (and lowercase variants)
    • skipWhen: Custom condition, return true to skip

Response cache

Output cache

Cache entire page or controller responses, with skip support for admins and authenticated users:

// On a controller action:
[OutputCache(Tags = [OutputCacheTag.SkipWhenAdmin])]
public IActionResult Index() { ... }

// On a razor page:
@attribute [OutputCache(Tags = [OutputCacheTag.SkipWhenAdmin])]

Available tags:

  • OutputCacheTag.SkipWhenAdmin — skips cache for admin users
  • OutputCacheTag.SkipWhenAuthenticated — skips cache for any authenticated user
Warning

SkipWhenAuthenticated and SkipWhenAdmin do not work on Razor Pages — controllers only.

Caveats

  • Auto-generated key is never user-specific — pass your own key containing userId/email to cache per user
  • null is never cached
  • Cache.Clear() may return default to concurrent callers during the brief reinitalization window
  • Auto-generated key is capped at 2000 characters and 64 scoped variables — exceeding either logs an error
  • Cache.Lock() is not a true lock — concurrent threads can still slip through
Tip

Pick duration by asking "what is the minimum time this data can be stale?" — always round down to the nearest CacheDuration value.

AppSettings

View all appsettings here