Tags Overview
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 marks. For instance in a store's product information library, the user wants to categorize the products according to the date of manufacture, price-range and country of production. All these keywords depict information based on which the products can be categorized.
Important
Starting from NCache Version 4.9.1, tags can be searched with wildcards.
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. Its 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. Considering the fact that the data is present in a large number, every time the user wants a particular item, the whole cache will be searched for it. That is where tags help. 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 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 three ways for 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 either of the tags will be retrieved.
3. With ALL Tags
This API is used when more than one tags are provided and the data matching ALL of the given tags is fetched. For example , 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.
Note
The wildcard expressions supported by NCache are ?
and *
.
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.Many-to-Many Grouping
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.Case Sensitive
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 a certain criteria. Groups provide logical partitioning of data in a hierarchical way. However tags have a few advantages over groups which make them a more efficient mechanism.
Following table shows the comparison between the functionalities of groups and tags.
Tags | Groups |
---|---|
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 can have a group and a sub-group; there is no third level |
Can be updated individually | Cannot be updated individually |
Independent of other tags | Sub-groups are dependent on groups |
Case-insensitive | Case-sensitive |
See Also
Retrieve Data from Cache with Tags
Remove Data from Cache with Tags
Search Data in Cache with SQL and Tags
Delete Data in Cache with SQL and Tags
Using Groups
Named Tags