.Net Distributed Caching 
Paul Fryer 
Software Architect, Fiserv
About Me
Portland 
Hipster
WHAT IS CACHE?
cache /kaSH/ 
verb 
–Store away in hiding or 
for future use.
Use of phrase “caching” in books, last 
200 years
WHAT IS A DISTRIBUTED CACHE?
Horizontal Scale
Online search interest for various 
cache providers
HOW TO CACHE
Pattern: Read Through Cache
Cache Scopes 
A = Application 
T = Tenant 
U = User 
S = Session
Where to Cache 
• Application / Tenant Data = Local Cache 
• Session / User Data = Distributed Cache
Cache Key Pattern 
{Scope}.{Identity}.{Uniqueness} 
A.WebUI.DefaultTheme 
A.WebUI.Exchanges.Page1.PageSize10 
T.TenantB.MaxHistory 
T.TenantC.ContactInformation 
U.johnB22.ProfileIcon 
U.sallyP1.LastPost 
S.2928328387.RequiresSecondFactorAuthentication 
S.2050988830.TransactionHistory.Page2.PageSize20
Time to Live 
• How critical is the data? 
– How current does it have to be? 
• Is eventual consistency ok?
TTL Performance Relationship 
Time to live 
Performance
Consistency 
• Events that invalidate cached data should cause 
the cached data to update or remove if possible. 
• You often only able to capture events within your 
application. 
• Underlying changes to the source can cause 
cached data to be out of sync. Mitigate this with 
appropriate TTL. 
• Pub/Sub capabilities exist on some distributed 
caches.
Code Examples 
• Adding a read through cache pattern to a slow 
service. 
• Consolidating the caching behavior into a 
reusable attribute. 
• Using a distributed cache to track statistics 
about connections, like number or requests 
per second. 
• Performance testing.
Resources 
• CacheSharp – abstraction layer that maps into 
multiple cache providers. Useful for establishing 
baselines and comparing different providers. 
• Redis Session State Provider – ASP.Net web 
application session state provider. Useful for web 
apps that want to move session state out of 
process. 
• CacheCow – HTTP Caching framework. Useful for 
implementing HTTP caching in web applications.
Connect 
• LinkedIn 
• My Blog

.Net Distributed Caching

  • 1.
    .Net Distributed Caching Paul Fryer Software Architect, Fiserv
  • 2.
  • 6.
  • 9.
  • 12.
    cache /kaSH/ verb –Store away in hiding or for future use.
  • 13.
    Use of phrase“caching” in books, last 200 years
  • 14.
    WHAT IS ADISTRIBUTED CACHE?
  • 15.
  • 16.
    Online search interestfor various cache providers
  • 17.
  • 18.
  • 19.
    Cache Scopes A= Application T = Tenant U = User S = Session
  • 20.
    Where to Cache • Application / Tenant Data = Local Cache • Session / User Data = Distributed Cache
  • 21.
    Cache Key Pattern {Scope}.{Identity}.{Uniqueness} A.WebUI.DefaultTheme A.WebUI.Exchanges.Page1.PageSize10 T.TenantB.MaxHistory T.TenantC.ContactInformation U.johnB22.ProfileIcon U.sallyP1.LastPost S.2928328387.RequiresSecondFactorAuthentication S.2050988830.TransactionHistory.Page2.PageSize20
  • 22.
    Time to Live • How critical is the data? – How current does it have to be? • Is eventual consistency ok?
  • 23.
    TTL Performance Relationship Time to live Performance
  • 24.
    Consistency • Eventsthat invalidate cached data should cause the cached data to update or remove if possible. • You often only able to capture events within your application. • Underlying changes to the source can cause cached data to be out of sync. Mitigate this with appropriate TTL. • Pub/Sub capabilities exist on some distributed caches.
  • 25.
    Code Examples •Adding a read through cache pattern to a slow service. • Consolidating the caching behavior into a reusable attribute. • Using a distributed cache to track statistics about connections, like number or requests per second. • Performance testing.
  • 26.
    Resources • CacheSharp– abstraction layer that maps into multiple cache providers. Useful for establishing baselines and comparing different providers. • Redis Session State Provider – ASP.Net web application session state provider. Useful for web apps that want to move session state out of process. • CacheCow – HTTP Caching framework. Useful for implementing HTTP caching in web applications.
  • 27.