Efficient data management necessitates the ability to quickly search for application data based on specific attributes, a need that becomes increasingly crucial as the data volume grows. Typically, databases use predefined fields for categorizing data which can also serve as indexes when caching data. However, there are times when grouping data is required based on attributes that are not explicitly present in the cache, such as tags or custom attributes.
NCache allows you to categorize and search your application data based on custom attributes. Along with traditional indexing, NCache offers the option to categorize data using Groups, Tags, and Named Tags, allowing for greater flexibility in data categorization and retrieval.
Cache Data Categorization via Groups
For a collection of cached items that can be identified by a Group name, you can create a Group. This name can help retrieve any item associated with that Group. For instance, you can create a Group with all the products associated with a certain customer or product category. Simply calling the name will cause NCache to return all the cached items affiliated with it. Please note that each item can only be associated with one Group. The example given below shows how customers from a specific region, (East Coast in this case) are grouped in an online store.
Moreover, you can also use SQL queries to search for cache objects contained in Groups using the keyword $Group$. The following code example demonstrates how to use a SQL query to view all customers from a particular region—in this instance, the West Coast.
In addition to increasing efficiency, Groups make it simple for users to retrieve or delete data based on these logical categories, boosting application scalability. Furthermore, Groups can cache commonly used data that match certain search criteria, avoiding the cost of running database searches repeatedly.
Cache Data Categorization via Tags
Tags in NCache provide a way to categorize cached items using multiple Tags. A cached object can have one or more Tags assigned to it, which can be used to retrieve the item. For instance, you can categorize items according to their region, language, or product features. Calling the name of a tag will cause NCache to return all associated cached items. Tags help relate metadata to the appropriate objects. For example, you can add a customer from the East Coast region and categorize this customer further using a VIP Customer tag. This process enhances data search and retrieval.
Similarly, you can query an item having a specific tag using the keyword $Tag$. The SQL query in the example below returns every item linked to the tag VIP Customers.
Using Tags give the user a high level of relevancy with each specific type. To know the other CRUD operations offered by Tags, please refer to the NCache Documentation.
Cache Data Categorization via Named Tags
A cached object can be assigned multiple Named Tags, via a list, which may then be used to retrieve the item. Each named tag has two parameters: a key that is a string representing the tag’s name and a value that is any primitive type. For example, you can assign Named Tags to items based on their price range or availability. Calling the tag name and value will cause NCache to return all the stored items that have the specified named tag when you need to get all the items with that tag.
Similar to groups and tags, you can retrieve items from the cache with Named Tags using object queries. When certain Named Tags are already added to items in the cache, NCache offers the user the opportunity to update those Named tags. Using NCache’s custom class, i.e., CacheItem, you can add data to the cache. As a property of the NamedTags class, the CacheItem enables you to specify additional specifications related to an item. In the example given below, a customer with VIP membership (with a 10% discount) use Named Tags that are set by assigning them as a property of the CacheItem.
When an item is added to the cache with Named Tags, you can easily retrieve it through the SQL query. In the following example, the user wishes to see all of the customers who have a 12% VIP membership discount.
Conclusion
NCache offers robust capabilities for effective data caching and searching through Groups, Tags, and Named Tags. This helps to categorize cached data based on specific attributes and retrieve them using NCache APIs or SQL-like queries. These features make them an even more compelling option for caching, as they enable faster data access, reduce database load, and improve the overall application performance. Experience the full benefits of these features and download NCache today!