Let's take a quick peek into data caching with NCache. Please note that NCache is industry's only 100% native .NET caching solution. Here's how NCache is typically deployed in the Enterprise for data caching. As you can see there's a separate caching tier that is extremely fast and scalable. NCache lets you add more servers to the caching tier if your application needs more transactional capacity.
Please also note these caches on your application server, these are called client caches. A Client Cache gives you InProc speed in a distributed caching environment. The goal here is for you to cache as much data as you can so that about 80 to 90% of the time you'll be able to find your data from the cache and avoid those expensive database trips. This improves your application performance and scalability.
Here is an overview of the data caching API by NCache, both .NET and Java. It's pretty straight forward. You connect to the cache by name, you do a cache.Get, Add, Insert, Remove. They are Async versions of it. Obviously this is a small subset of the overall cache.
The next thing to talk about is what type of data to cache. The first is Reference Data. Reference Data is actually data that does not change very frequently. These are your product catalogs. It is not static data but it changes maybe in hours, days, or weeks. And, you should cache the entire data sets, for example, all the products. So that you can later on run SQL queries on the cache.
The second type of data to cache is the Transactional Data. This data is created at runtime. This is your customers, your orders. And, this data changes very frequently but you can still cache it for like 15 seconds, a few minutes, 5 minutes, 10 minutes. Usually for the duration of your user session.
The next question is how do you cache this data? Well, you cache it as either as objects, your .NET or Java or any other language objects. Or if you're using collections, .NET or Java collections. You can cache the entire collection as one object or you can cache every item of the collection separately.
NCache also gives you very powerful distributed data structures like List, Queue, Set, Dictionary, Counter. These allow you to cache complex data together in the cache.
Well, one of the first things you have to keep in mind is to keep the cache fresh because this data also exists in the database and the cache should be consistent with the database. There are four ways that NCache provides you.
Number one is Expirations where you expire the data based on the nature of the data either reference or transactional data.
Number two is that NCache gives you two event based ways to synchronize the cache with the database. One is SQL Dependency and second is Oracle Cache Dependency. NCache also gives you a polling based way of synchronizing the cache with the database.
A third way that you can keep the cache fresh is to synchronize the cache with your custom data source. This obviously involves some custom code that you have to provide to NCache so NCache calls it.
Number four is for NCache to manage relationships of data in the cache. So, if you have one-to-one, one-to-many type of relationships in the cache, so if many item changes or if the one item changes the many side probably also need to be updated. So, NCache manages that.
Well, once you start caching a lot of data, that NCache being a key value store just fetching everything based on keys is not very convenient. So, that is why NCache gives you powerful features like Group, Tag, Named Tags so that you can logically group them and fetch them later on.
You can also use SQL queries to search based on object attributes, groups, tags, and named tags.
If you have a .NET application then you can use LINQ Queries for that.
NCache also provides you a Read-Through Cache that simplifies your application. In a read-through cache when you do a cache.Get and the cache does not have the data it actually calls your custom code a read-through handler to go and fetch that data from the database.
There is also Write-Through Cache which is when you do a cache.Add, Insert, or Remove, NCache calls your custom code, again a write-through handler to go and update the database.
Write-behind is basically write-through done asynchronously so your application does not have to wait for the database to be updated and it improves your application performance.
NCache also provides you a cache that is self-sufficient which means it stays populated and fresh on its own. There is a Cache Loader which is called upon startup. This is your custom code NCache calls it to load your data from your database. You can define multiple data sets for parallel loading.
There is also Cache Refresher that is called repeatedly either on daily, weekly, monthly, or any custom interval or even on demand. And, every time it is called it refreshes the cache. Refreshing means it updates existing data or adds new data. Again this is your custom code that goes and does all of this.
For .NET application NCache provides integrations with EF Core. NCache has implemented EF Core Extension Methods, so you have an EF Core cache that you can use seamlessly. NCache also has provided an NHibernate Second Level Cache for you to use. And, for legacy .NET applications NCache has provided an EF6 Cache provider.
For Java applications NCache has provided a Hibernate Second Level Cache for you to use. For spring applications NCache gives you Spring Cache which you can use through annotations. NCache has also implemented the popular JCache API in the Java landscape.
Please contact us to schedule a demo to learn about NCache Architecture and features in detail and also about the strategy and how you should use NCache in your application. Thank you very much!
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.