Items in a cache having a relation between them or falling under the similar category can be grouped in NCache using NCache "Groups" feature. Using Groups, you can logicaly partition your data for better efficiency.
Why to Use Groups
Groups improve efficiency as well as provide the user with an ease to fetch or remove data in logical groups. This helps reduce time consumption yielding faster results. Moreover, if the data is grouped according to any logical criteria, the network trips are reduced since the database does not need to be accessed every time. This makes it cost effective as well.
When to Use Groups
Lets assume a scenario, in which there is a large number of customers for a particular company and the user wants to categorize the customers according to the revenue generated. For example, the first category must add the customers whose revenue generated was above $1000, to the cache as "Important Customers".
This can be done by executing an SQL query over the database which obtains the result set containing those customers and in order to save the effort of executing the SQL command every time on the entire database, add the result set to the cache with a group name so the data resides under that particular group.
The table below is an illustration of the above scenario.
Retrieve/Remove using Groups
Using groups, you can fetch or remove all items belonging to a group. You can also just fetch the keys and then only fetch a subset of them. You can perform addition, update, removal, retrieval while specifying a group identifier.
Groups can be updated
Group identifiers can be updated. For updating, re-insert the item in the cache with the updated group name.
Group hierarchy is one level
There is no further level of hierarchy after group. Cache items can be logically separated by a single group only.
Groups are case-sensitive.
Groups can only be of string data type.
Groups do not Overlap
Groups do not overlap and hold distinct names.