Download - .Net Distributed Caching

Transcript
Page 1: .Net Distributed Caching

.Net Distributed Caching

Paul Fryer

Software Architect, Fiserv

Page 2: .Net Distributed Caching

About Me

Page 3: .Net Distributed Caching
Page 4: .Net Distributed Caching
Page 5: .Net Distributed Caching
Page 6: .Net Distributed Caching

Portland Hipster

Page 7: .Net Distributed Caching
Page 8: .Net Distributed Caching
Page 9: .Net Distributed Caching

WHAT IS CACHE?

Page 10: .Net Distributed Caching
Page 11: .Net Distributed Caching
Page 12: .Net Distributed Caching

cache /kaSH/

verb

–Store away in hiding or for future use.

Page 13: .Net Distributed Caching

Use of phrase “caching” in books, last 200 years

Page 14: .Net Distributed Caching

WHAT IS A DISTRIBUTED CACHE?

Page 15: .Net Distributed Caching

Horizontal Scale

Page 16: .Net Distributed Caching

Online search interest for various cache providers

Page 17: .Net Distributed Caching

HOW TO CACHE

Page 18: .Net Distributed Caching

Pattern: Read Through Cache

Page 19: .Net Distributed Caching

Cache Scopes

A = Application

T = Tenant

U = User

S = Session

Page 20: .Net Distributed Caching

Where to Cache

• Application / Tenant Data = Local Cache

• Session / User Data = Distributed Cache

Page 21: .Net Distributed Caching

Cache Key Pattern

{Scope}.{Identity}.{Uniqueness}

A.WebUI.DefaultThemeA.WebUI.Exchanges.Page1.PageSize10

T.TenantB.MaxHistoryT.TenantC.ContactInformation

U.johnB22.ProfileIconU.sallyP1.LastPost

S.2928328387.RequiresSecondFactorAuthenticationS.2050988830.TransactionHistory.Page2.PageSize20

Page 22: .Net Distributed Caching

Time to Live

• How critical is the data?

– How current does it have to be?

• Is eventual consistency ok?

Page 23: .Net Distributed Caching

TTL Performance Relationship

Time to live

Perf

orm

ance

Page 24: .Net Distributed Caching

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.

Page 25: .Net Distributed Caching

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.

Page 26: .Net Distributed Caching

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.