Group/sub-group is a hierarchical way of grouping cached items. A Group is a logical partition of data; this partition can have a sub division (sub group) or can be just a major division (group), it is a two level grouping.
Why to Use Groups
Groups improve efficiency as well as provide the user with an ease to fetch or remove data in logical groups which reduces time consumption. Moreover, if the data is grouped according to any logical criteria, the network trips are reduced since the database doesn't need to be accessed every time which is also cost effective.
When to Use Groups
A single group can have none or more sub-groups. Its not necessary for every group to have a subgroup whereas all subgroups belong to any group.
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.
Now the user wants the further sub-division of these important customers on the basis of region where a sub-group "East Coast Customers" includes the customers of the east-coast region whereas the sub-group "West Coast Customers" include the customers of the west-coast region. The table below is an illustration of the whole scenario.
The groups and sub-groups here form a hierarchy where the sub-groups can only belong to the group.
- 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 specifying group identifier and/or its sub group identifier.
NCache supports multiple sub groups within one group. But cache operations cannot be performed only with the sub group identifier, as two different groups can have the same sub group identifier.
Group cannot be updated
Group identifiers cannot be updated. For its update, remove cache key and then insert with new group identifier.
Group and Sub-Group hierarchy is one level
There is no further level of hierarchy after subgroup. Cache items can be logically separated by a single group and single sub group only.
Groups and subgroups are case-sensitive.
Groups and sub-groups can only be of string data type.
Groups do not Overlap
Groups do not overlap but multiple groups might have sub-groups with similar names.