Tags Properties and Usage Overview
This feature is only available in NCache Enterprise.
Tags are string-based identifiers that can be used to associate keywords (metadata) with your cache items. You can mark your data with these keywords and later retrieve or remove your cache items with the help of these keyword(s). For instance, in a store's product information library, the user wants to categorize the products according to the Date of Manufacture and Country of Production. All these keywords depict information based on which the products can be categorized.
NCache now also provides support for wildcard searching of tags.
Why to Use Tags
Using tags can help the user associate keywords with cache items so the user can easily access the relevant data. The advantages of using tags include providing the user with a high level of relevance with the particular type. Moreover, the tagged data makes it easier for the user to locate the bookmarked data which improves efficiency, reduces time consumption, and reduces network trips which makes it cost-effective. It is a helpful approach if the user wants to organize data.
When to Use Tags
Let's suppose your cache contains the data of a large number of customers. Because the data is present in a large number, every time the user wants a particular item, the whole cache will be searched for it. Using tags, the data can be tagged with various identifiers which can later be used to get the data associated with that tag.
The table below contains the data of customers and a tag East Coast Customers is added with the customers belonging to the East Coast region and West Coast Customers for the customers of the West Coast region.
Furthermore, the data is categorized based on the priority of customers. There may be a few important customers belonging to either of the regions, so an additional tag of Important Customers is added with them.
There are customers with only one tag as well as customers with more than one tags. For example, the customer with CustomerID ALFKI contains the tag East Coast Customers and tag Important Customers. Whereas the customer with CustomerID BOLID contains only one tag, i.e., West Coast Customers.
Flexibility for Fetching Data with Tags
NCache provides four ways of fetching data based on the tags.
1. With ONLY One Tag
The data is fetched based on the tag provided. A single tag is provided and all the data associated with that tag will be fetched. For example, in order to fetch the customers belonging to the East Coast region, the tag East Coast Customers is provided.
2. With ANY One Tag
This API is used when more than one tags are provided and the data matching ANY of the provided tags is fetched. For example, providing the tags Important Customers, East Coast Customers, and West Coast Customers, the data of customers containing both of the tags will be retrieved.
3. With ALL Tags
This API is used when more than one tag is provided and the data matching ALL of the given tags is fetched. For example, by providing the tags Important Customers and East Coast Customers, the data of customers containing both of the tags will be retrieved.
4. With Wildcard Characters
Since tags are string-based identifiers, NCache provides the flexibility of searching data with specific patterns on the string, i.e., data is retrieved based on wildcard searching. A wildcard allows you to search for strings containing or starting/ending with any characters.
For example, searching the cache with tag Customers will retrieve all the customers with tags East Coast Customers, West Coast Customers, and Important Customers. If the cache is searched with the tag ??st Coast Customers, all the items with the tags East Coast Customers and West Coast Customers are retrieved. The special characters supported in wild search by NCache are:
*: Used as a substitute for zero or more characters in the string.
?: Used as a substitute for a single character in the string.
Properties of Tags
Retrieve/Remove Using Tags
These identifying marks can help you in finding and/or removing items from the cache.
Support for Multiple Tags
You can tag more than one keyword with any cache item. The number of tags can be infinite.
Support for Wildcard Search
NCache now provides support for searching tags with wildcard expressions.
Tags provide a many-to-many grouping where one tag can contain multiple cached items and one cached item can belong to multiple tags. NCache lets you associate one or more tags with a single item.
Tags are case insensitive.
Query Using Tags
NCache also supports tags in queries.
Comparison Between Tags and Groups
Tags as well as groups have the same primary functionality of providing partitioning of data based on certain criteria. Groups provides logical partitioning of data in a hierarchical way.
However, tags have a few advantages over groups, making them more efficient. A single item can have multiple qualities/attributes associated with them in the form of tags. If you employ both features, make sure to keep them unique.
The following table shows the comparison between the functionalities of groups and tags.
|Provided in the form of an array of tags||Provided in the form of string|
|String based only||String based only|
|An item can have infinite number of tags||An item have can only one group|
|Independent of other tags||Independent of other groups|