Modern problems require modern solutions, right? And fast performance has always been a problem – call it trivial or modern. NCache is a quick fix for your critical problems such as performance and scalability. It works efficiently and covers all the problematic areas in your application, however, caching has its primary purpose for applications that are more read intensive. This blog thoroughly explains how NCache is the best fit for your read intensive applications.

The Need of Caching

Let’s start with the beginning and see why is caching needed in the first place? Its simple answer is the databases’ response time. It is a given that the primary storage (your database) containing all the data at one place can choke due to a higher response rate. What solves it? Caching, as it comes as an in-memory storage and provides you a faster response time.

Secondly, cache being distributed in nature, has no single point of failure unlike database. Your data is distributed and that increases the scalability. The load is divided and thus less chances of requests making the servers choke.

Read intensive applications using NCache

Figure 1: Read Intensive Applications with NCache

Given the above facts, we have established that NCache is an in-memory storage and your data is a part of the cache. So, caching is the best fit for situations where your write intensity is not very high and the read intensity is relatively higher. Let us take an example of a website containing information about the transport system. The bus fares or the timings are usually static and there is a very rare chance of fares being updated. Such applications having more read intensive data have a rich set of features provided by NCache for performing faster read operations.

NCache as a Read Intensive Cache Store

Applications having a read intensive nature have NCache to perform all the read operations at a much faster rate. NCache has a rich set of features that cater to any kind of read operations albeit fetching a single item or fetching items in bulk. Once the data is added to the cache from the database, all the fetch operations go directly to the cache for higher performance and scalability.

Get Operations in NCache

NCache provides various overloads of Get() method to fetch data from the cache against a specific key. These operations are synchronous in nature and returns a type object casted according to your custom logic. In case no item exists in the cache, it returns null. Look at the code below to show the normal Get() method fetching a single item from the cache:

Get Bulk items from Cache

Similarly bulk items can also be fetched from the cache using the GetBulk() method. Using this, you can fetch a bulk number of items from the cache using a single call. You can then cast the returned template as your custom type. Look at the code below to see how can items be fetched in bulk. Items are fetched from the database and then all the further read operation calls are sent directly to the cache.

Fetch Items using Keywords

You can also fetch items using keywords attached to them for an effective search. You mark your data with certain string-based keywords and retrieve the items with the help of these keywords. For example, you want to group certain customers using the region they belong to such as East Coast or West Coast. The certain feature set provided by NCache for this purpose is:

Let us look at the code below to see how you add named tags with an item and then fetch the items using those named tags. This particular example fetched items with a flash discount on them.

Search Cache using SQL

When it comes to fetching items from a particular database, queries are an effective way to search with the certain criteria. NCache fully understanding the need of queries lets you fetch items from the cache using SQL like queries. You need to index the particular item in the cache as cache does not create indexes on its own unlike database. But you are good to go with SQL search once data is indexed. Following are the things supported in NCache queries:

  • Basic query operators (=, ==, !=. LIKE, NOT LIKE)
  • Logical operators (AND, OR, NOT)
  • Aggregate Functions (SUM, COUNT, AVG, MIN, MAX)
  • Miscellaneous

Look at the code below to see how SQL like queries are used to search through the cache. The particular example shows the GROUP BY command where the products with price greater than 10 and the category Beverages are retrieved and grouped.

Search Cache using LINQ

Similar to SQL, NCache provides support for writing queries in LINQ format to search the cache. NCache LINQ provider converts LINQ related query into NCache’s extended SQL format and returns the results accordingly after transforming it in LINQ format. There are two types of syntax for writing LINQ query:

  • Lambda Expression
  • Simple LINQ query expression

However, just like SQL you need to define indexes for the searchable cache data for your query to run smoothly. Look at the code example below to see how LINQ query is used to fetch an object from the cache.

Concluding the Blog

Learning about read intensive application and increasing their performance, NCache comes off as a powerful caching solution. It boosts the speed, enhancing the performance, scalability and reliability with a rich set of features. Please check out other NCache features from our website.

NCache Details                                    Download NCache

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment