Alachisoft
.NET Performance Solutions

How to Handle Relational Data
in a Distributed Cache

Iqbal Khan
iqbal@alachisoft.c...
Alachisoft

Following Applications Need Scalability
1.

ASP.NET Apps


2.

WCF & .NET Web Services


3.

To quickly proc...
Alachisoft

Data Storage is Scalability Bottleneck
ASP.NET/WCF Example

App Database

ASP.NET/WCF Servers

Database Server...
Alachisoft

The Solution

Scalable In-Memory Distributed Cache

NCache
NCache

www.alachisoft.com

4
Alachisoft

What is an In-Memory Distributed Cache?
1.

Cluster of multiple inexpensive cache servers


2.

Synchronizes ...
Alachisoft

NCache: In-Memory Distributed Cache
ASP.NET Web Apps

WCF Web Services

Grid Computing Apps
(.NET)

.NET Serve...
Alachisoft

What Data to Cache?
1.

Reference Data


2.

Transactional Data


3.

Does not change very frequently (but i...
Alachisoft

Challenge: Cache versus Relational Data


Cache provides a Hashtable-like interface





Each item is sepa...
Alachisoft

Peek into Caching API


Read from the Cache






Add to the Cache






object obj = cache.Get(“myKe...
Alachisoft

First Step: Use CacheDependency


Lets you manage relationships in the cache




One cached item depends on...
Alachisoft

Second Step: Use Object Relational Mapping


Benefits of O/R Mapping





Benefits of O/R Mapping Tools

...
Alachisoft

Mapping Domain Objects to Database
Data Model

NCache

www.alachisoft.com

12
Alachisoft

What is a Primary Object?


It is a domain object




Starting point for the application





Mapped to ...
Alachisoft

Mapping Domain Objects to Database

NCache

www.alachisoft.com

14
Alachisoft

1-1/n-1 Relationships in Distributed Cache


Strategy 1: cache related object with primary object



Strateg...
Alachisoft

1-1/n-1 Relationships in Distributed Cache
Cache related object with primary object

NCache

www.alachisoft.co...
Alachisoft

1-1/n-1 Relationships in Distributed Cache
Cache related object separately

NCache

www.alachisoft.com

17
Alachisoft

1-n Relationships in Distributed Cache


Strategy 1: cache related objects collection with primary object


...
Alachisoft

1-n Relationships in Distributed Cache
Cache related object collection separately

NCache

www.alachisoft.com
...
Alachisoft

1-n Relationships in Distributed Cache
Cache each object in related collection separately

NCache

www.alachis...
Alachisoft

m-n Relationships in Distributed Cache


Many-to-many relationships don’t exist in domain objects



Instead...
Alachisoft

Handling Collections in Distributed Cache


Scenario 1: cache entire collection as one item



Scenario 2: c...
Alachisoft

Handling Collections in Distributed Cache
Cache entire collection as one item

NCache

www.alachisoft.com

23
Alachisoft

Handling Collections in Distributed Cache
Cache each collection item separately

NCache

www.alachisoft.com

2...
Alachisoft

Hands on Demo

NCache

www.alachisoft.com

25
Alachisoft

Some Object Caching Features


Expirations






Locking (Pessimistic & Optimistic)





Lock/Unlock fo...
Alachisoft

Synchronize Cache with Data Sources


Synchronize with Relational Databases (SQL, Oracle, etc.)







Sq...
Alachisoft

Data Grouping in the Cache


Group/Subgroup



Tags



Named Tags

NCache

www.alachisoft.com

28
Alachisoft

Searching the Cache


Parallel Queries with Object Query Language (OQL)




Parallel LINQ Queries




SQL...
Alachisoft

Some Other Features


NHibernate L2 Cache Provider




Entity Framework L2 Cache




Plug into NHibernate...
Alachisoft

What to Do Next?






Find more about NCache
Download 60-day Trial
Request a Personalized LIVE Demo
Read ...
Upcoming SlideShare
Loading in...5
×

Handling Relational Data in a Distributed Cache

927

Published on

Most ASP.NET applications that needs scalability are data intensive and use relational database as their data store. This presentation provides information about relational data, object relational mapping, its management, caching strategies and handling collections in a distributed cache.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
927
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Handling Relational Data in a Distributed Cache

  1. 1. Alachisoft .NET Performance Solutions How to Handle Relational Data in a Distributed Cache Iqbal Khan iqbal@alachisoft.com Ph: +1 (925) 236-2125 www.alachisoft.com 1
  2. 2. Alachisoft Following Applications Need Scalability 1. ASP.NET Apps  2. WCF & .NET Web Services  3. To quickly process very large amounts of data thru distribution Grid Computing Apps  5. To handle millions of requests Big Data Apps  4. To handle millions of users To process very large computations thru distribution Other .NET Server Apps  NCache To handle millions of requests www.alachisoft.com 2
  3. 3. Alachisoft Data Storage is Scalability Bottleneck ASP.NET/WCF Example App Database ASP.NET/WCF Servers Database Servers Data Access Scale Web Farm Web Clients Http Calls ... NCache Load Balancer www.alachisoft.com ASP.NET Session Storage 3
  4. 4. Alachisoft The Solution Scalable In-Memory Distributed Cache NCache NCache www.alachisoft.com 4
  5. 5. Alachisoft What is an In-Memory Distributed Cache? 1. Cluster of multiple inexpensive cache servers  2. Synchronizes cache updates across all cache servers  3. Cache updates are immediately visible from all cache servers Linearly scales transaction & memory capacity  4. Pools their memory and CPU into one logical capacity Just add more cache servers to grow capacity Replicates data for reliability  NCache Intelligent replication without compromising performance & scalability www.alachisoft.com 5
  6. 6. Alachisoft NCache: In-Memory Distributed Cache ASP.NET Web Apps WCF Web Services Grid Computing Apps (.NET) .NET Server Apps Distributed Cache Cluster Memory pooled from all cache servers Scale Horizontally Windows 2008/2012 (64-bit) Filesystem NCache Database Servers www.alachisoft.com Mainframe 6
  7. 7. Alachisoft What Data to Cache? 1. Reference Data  2. Transactional Data  3. Does not change very frequently (but is not static) Changes frequently (as frequently as in a few seconds) Most Cached Data is Relational  NCache Comes from relational databases www.alachisoft.com 7
  8. 8. Alachisoft Challenge: Cache versus Relational Data  Cache provides a Hashtable-like interface    Each item is separate and has a “key” and a “value”. “Value” is usually an “object” Relational data has relationships between entities  NCache This is a challenge for your application www.alachisoft.com 8
  9. 9. Alachisoft Peek into Caching API  Read from the Cache     Add to the Cache     object obj = cache.Get(“myKey”); object obj = cache[“myKey”]; bool isPresent = cache.Contains(“myKey”); cache.Add(“myKey”, obj); cache.Insert(“myKey”, obj); cache[“myKey”] = obj; Remove from the Cache  NCache object obj = cache.Remove(“myKey”); www.alachisoft.com 9
  10. 10. Alachisoft First Step: Use CacheDependency  Lets you manage relationships in the cache   One cached item depends on another   A depends on B and B depends on C. Change in C triggers both A & B Feature introduced by ASP.NET Cache   If target cached item updated/removed, dependent automatically removed Cascaded dependencies possible   Cache keeps track of a one-way “dependency” between cached items Key based dependency is our focus here NCache also provides it NCache www.alachisoft.com 10
  11. 11. Alachisoft Second Step: Use Object Relational Mapping  Benefits of O/R Mapping    Benefits of O/R Mapping Tools     Cut down development time Improve code quality in persistence & domain objects Simplifies programming. No need to directly use ADO.NET Which O/R Mapping Tools to Use?    Simplifies programming by mapping domain objects to data model Promotes code reuse of persistence and domain objects Entity Framework (Microsoft) NHibernate (Open Source) At Least Map Domain Objects to Database    NCache Map to database entities Capture relationships in these objects Transform DataReader or DataTable into domain objects www.alachisoft.com 11
  12. 12. Alachisoft Mapping Domain Objects to Database Data Model NCache www.alachisoft.com 12
  13. 13. Alachisoft What is a Primary Object?  It is a domain object   Starting point for the application    Mapped to a table in the database Application fetches this objects first All other objects fetched in relation to this object All other objects fetched in relation to this object  NCache One-to-many and many-to-one relationships www.alachisoft.com 13
  14. 14. Alachisoft Mapping Domain Objects to Database NCache www.alachisoft.com 14
  15. 15. Alachisoft 1-1/n-1 Relationships in Distributed Cache  Strategy 1: cache related object with primary object  Strategy 2: cache related object separately NCache www.alachisoft.com 15
  16. 16. Alachisoft 1-1/n-1 Relationships in Distributed Cache Cache related object with primary object NCache www.alachisoft.com 16
  17. 17. Alachisoft 1-1/n-1 Relationships in Distributed Cache Cache related object separately NCache www.alachisoft.com 17
  18. 18. Alachisoft 1-n Relationships in Distributed Cache  Strategy 1: cache related objects collection with primary object   Strategy 2: cache related objects separately separately   Cache entire collection as part of the primary object Cache entire collection as one item but separately Strategy 3: cache related objects from collections separately  NCache Cache each item of the collection separately www.alachisoft.com 18
  19. 19. Alachisoft 1-n Relationships in Distributed Cache Cache related object collection separately NCache www.alachisoft.com 19
  20. 20. Alachisoft 1-n Relationships in Distributed Cache Cache each object in related collection separately NCache www.alachisoft.com 20
  21. 21. Alachisoft m-n Relationships in Distributed Cache  Many-to-many relationships don’t exist in domain objects  Instead, represented by two one-to-many relationships   E.g. Customer->Orders and Product->Orders Intermediary object contains many-to-one references  NCache E.g. Order has a reference to Customer and Product www.alachisoft.com 21
  22. 22. Alachisoft Handling Collections in Distributed Cache  Scenario 1: cache entire collection as one item  Scenario 2: cache each collection item separately NCache www.alachisoft.com 22
  23. 23. Alachisoft Handling Collections in Distributed Cache Cache entire collection as one item NCache www.alachisoft.com 23
  24. 24. Alachisoft Handling Collections in Distributed Cache Cache each collection item separately NCache www.alachisoft.com 24
  25. 25. Alachisoft Hands on Demo NCache www.alachisoft.com 25
  26. 26. Alachisoft Some Object Caching Features  Expirations    Locking (Pessimistic & Optimistic)    Lock/Unlock for pessimistic locking (writer-lock) Object versioning for optimistic locking (reader-lock) Bulk Operations   Absolute-time + idle-time Auto-reload data on expiration (if read-thru enabled) Bulk Get, Add, Insert, and Remove Async Operations  NCache Async Add, Insert, and Remove www.alachisoft.com 26
  27. 27. Alachisoft Synchronize Cache with Data Sources  Synchronize with Relational Databases (SQL, Oracle, etc.)     SqlDependency OracleDependency DbDependency Synchronize with non-Relational Data Sources   NCache File based Cache Dependency Custom Cache Dependency www.alachisoft.com 27
  28. 28. Alachisoft Data Grouping in the Cache  Group/Subgroup  Tags  Named Tags NCache www.alachisoft.com 28
  29. 29. Alachisoft Searching the Cache  Parallel Queries with Object Query Language (OQL)   Parallel LINQ Queries   SQL-like query language to search cache based on object attributes Standard LINQ queries can search the cache Indexing Object Attributes for Querying  NCache Create indexes on object attributes to speed up queries www.alachisoft.com 29
  30. 30. Alachisoft Some Other Features  NHibernate L2 Cache Provider   Entity Framework L2 Cache   Plug into NHibernate application without any code change Plug into Entity Framework application without any code change Dynamic Compact Serialization   NCache Faster and more compact then regular .NET serialization No code writing required www.alachisoft.com 30
  31. 31. Alachisoft What to Do Next?     Find more about NCache Download 60-day Trial Request a Personalized LIVE Demo Read product Documentation Thank You NCache 4.1 www.alachisoft.com 31

×