Method GetKeysByTag
GetKeysByTag(Tag)
Gets all the keys with the specified tag.
Declaration
public virtual ICollection GetKeysByTag(Tag tag)
Parameters
Type | Name | Description |
---|---|---|
Tag | tag | The tag to search with. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns collection containing the cache keys. |
Examples
The following example demonstrates how to get the keys with the specified tag.
Cache cache = NCache.InitializeCache("myCache");
Tag tag = new Tag("Sports");
ICollection keys = cache.GetKeysByTag(tag);
GetKeysByTag(String)
Gets all the keys with the wild card supported tag.
Declaration
public virtual ICollection GetKeysByTag(string wildCardExpression)
Parameters
Type | Name | Description |
---|---|---|
System.String | wildCardExpression | The wild card Expression to search with. We provide two wildcard expressions i.e with '' and '?'. '' specifies that a word can be at the start or end of the expression where as '?' specifies missing character. Number of '?' specify the number of missing characters. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns collection containing the cache keys. |
Examples
Suppose you have information of players in your cache who play different sports. You have added a tag with each player entry that contains contains information about what sport the play like "Sports:Cricket", "Sports:Basketball" etc. The following example demonstrates how to get keys of all players. Say the keys are PlayerIds:
Cache cache = NCache.InitializeCache("myCache");
ICollection keys = cache.GetKeysByTag("Sports*"); //will return a list containing PlayerIds of all players.
//Now you want to get PlayerIds of players who play Cricket
ICollection cricketPlayers = cache.GetKeysByTag("*Cricket");