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.
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. 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. 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
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. 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. 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. 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. 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. 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. 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
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
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
20. Alachisoft
1-n Relationships in Distributed Cache
Cache each object in related collection separately
NCache
www.alachisoft.com
20
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. 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
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. 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. 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