Tags Properties and Usage 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 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.
Why to Use Tags
Using Tags can help the user associate keywords with cache items to 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, improving efficiency and saving time. It also reduces unnecessary network requests, making the process more cost-effective. This approach is especially helpful for users who want to organize their data effectively.
When to Use Tags
Let's suppose your cache contains the data of a large amount 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 to them.
There are customers with only one Tag as well as customers with more than one Tag. For example, the customer with CustomerID ALFKI contains the Tag East Coast Customers and also the 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 to fetch data based on the Tags.
1. With ONLY One Tag
The data is fetched based on the provided Tag. 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 multiple 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 any one or more of these Tags will be retrieved.
3. With ALL Tags
This API is used when multiple Tags are 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 the pattern *Customers will retrieve all the customers with Tags like East Coast Customers, West Coast Customers, and Important Customers. If the cache is searched using ??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
Following are the properties of Tags:
Retrieve/Remove Using Tags
These Tags 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 Insensitive
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 provide 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 it 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.
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 have can only one Group |
Independent of other Tags | Independent of other Groups |
See Also
Retrieve Cache Data with Tags
Remove Cache Data with Tags
Search Tag Data in Cache with SQL
Delete Tag Data from Cache with SQL
Use Groups for Logical Data Grouping
Named Tags with Cache Data