Skip to content

Fast.Cache public API ​

Targets: net8.0;net9.0;net10.0. Select a type in the page outline to find its declaration and members. See the module guide for configuration, examples, and constraints.

Reference version 3.5.40. Source commit a8bd407bf5f6b811da7fb7bd1db827f4da119a94.

Fast.Cache.DefaultCacheContextLocator ​

Source · Targets: net8.0, net9.0, net10.0

csharp
[SuppressSniffer]
public class DefaultCacheContextLocator : ICacheContextLocator

Default cache context locator

Fast.Cache.DefaultCacheContextLocator.ServiceName ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public string ServiceName { get; }

Documentation is inherited from an interface or base class; consult that declaration.

Fast.Cache.ICacheContextLocator ​

Source · Targets: net8.0, net9.0, net10.0

csharp
[SuppressSniffer]
public interface ICacheContextLocator

Cache context locator

Fast.Cache.ICacheContextLocator.ServiceName ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string ServiceName { get; }

Service name

Fast.Cache.IServiceCollectionExtension ​

Source · Targets: net8.0, net9.0, net10.0

csharp
[SuppressSniffer]
public static class IServiceCollectionExtension

Cache extensions for IServiceCollection

Fast.Cache.IServiceCollectionExtension.AddCache ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public static IServiceCollection AddCache(this IServiceCollection services, string section = "RedisSettings")

Adds cache services

  • Parameter services: The service collection to add services to
  • Parameter section: JSON configuration section key; defaults to RedisSettings
  • Returns: Returns services for chaining

Fast.Cache.IServiceCollectionExtension.AddCache ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public static IServiceCollection AddCache(this IServiceCollection services, Action<RedisSettingsOptions> optionAction)

Adds cache services

  • Parameter services: The service collection to add services to
  • Parameter optionAction: Configures the default Redis connection directly and named connections through Services.
  • Returns: Returns services for chaining

Fast.Cache.ICache ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public interface ICache : ICache<DefaultCacheContextLocator>

Default cache service

Fast.Cache.ICache ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public interface ICache<out CacheContextLocator> where CacheContextLocator : ICacheContextLocator, new()

Cache service

  • Type parameter CacheContextLocator: Cache context locator type used to isolate cache configurations

Fast.Cache.ICache.Prefix ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string Prefix { get; }

Prefix

Fast.Cache.ICache.Client ​

Source · Targets: net8.0, net9.0, net10.0

csharp
CSRedisClient Client { get; }

Current CSRedis cache client

Remarks: The cache service owns this client; callers must not dispose it. After a successful reload, new operations use the new generation, while borrowed old generations remain until service disposal. Frequent reloads retain multiple pools and are not suitable for per-request switching. No generation may be used after the service shuts down.

Fast.Cache.ICache.ContextLocator ​

Source · Targets: net8.0, net9.0, net10.0

csharp
CacheContextLocator ContextLocator { get; }

Cache context locator

Fast.Cache.ICache.Del ​

Source · Targets: net8.0, net9.0, net10.0

csharp
long Del(params string[] key);

Deletes cache entries for the specified keys

  • Parameter key: Cache key
  • Returns: The number of entries actually deleted

Fast.Cache.ICache.DelAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<long> DelAsync(params string[] key);

Asynchronously deletes cache entries for the specified keys

  • Parameter key: Cache key
  • Returns: A task whose result is the number of cache entries actually deleted

Fast.Cache.ICache.DelByPattern ​

Source · Targets: net8.0, net9.0, net10.0

csharp
long DelByPattern(string pattern);

Deletes all cache entries matching a pattern

Remarks: Scans and deletes all matching keys. A large key set may block Redis; avoid calling this on high-traffic paths.

  • Parameter pattern: Pattern used to match target entries
  • Returns: The number of entries actually deleted

Fast.Cache.ICache.DelByPatternAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<long> DelByPatternAsync(string pattern);

Asynchronously deletes all cache entries matching a pattern

Remarks: Scans and deletes all matching keys. A large key set may block Redis; avoid calling this on high-traffic paths.

  • Parameter pattern: Pattern used to match target entries
  • Returns: A task whose result is the number of matching cache entries actually deleted

Fast.Cache.ICache.Exists ​

Source · Targets: net8.0, net9.0, net10.0

csharp
bool Exists(string key);

Checks whether the specified cache key exists

  • Parameter key: Cache key
  • Returns: Returns true when the condition is met; otherwise false

Fast.Cache.ICache.ExistsAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<bool> ExistsAsync(string key);

Asynchronously checks whether the specified cache key exists

  • Parameter key: Cache key
  • Returns: Returns true when the condition is met; otherwise false

Fast.Cache.ICache.Get ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string Get(string key);

Gets the cached value for the specified key

  • Parameter key: Cache key
  • Returns: The retrieved cache value

Fast.Cache.ICache.Get ​

Source · Targets: net8.0, net9.0, net10.0

csharp
T Get<T>(string key);

Gets the cached value for the specified key

  • Parameter key: Cache key
  • Type parameter T: Type of the cached value
  • Returns: The retrieved cache value

Fast.Cache.ICache.GetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<string> GetAsync(string key);

Asynchronously gets the cached value for the specified key

  • Parameter key: Cache key
  • Returns: A task whose result is the retrieved cache value

Fast.Cache.ICache.GetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<T> GetAsync<T>(string key);

Asynchronously gets the cached value for the specified key

  • Parameter key: Cache key
  • Type parameter T: Type of the cached value
  • Returns: A task whose result is the retrieved cache value

Fast.Cache.ICache.Set ​

Source · Targets: net8.0, net9.0, net10.0

csharp
bool Set(string key, object value);

Stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.Set ​

Source · Targets: net8.0, net9.0, net10.0

csharp
bool Set(string key, object value, int expireSeconds);

Stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Parameter expireSeconds: Lifetime in seconds
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.Set ​

Source · Targets: net8.0, net9.0, net10.0

csharp
bool Set(string key, object value, TimeSpan expireTimeSpan);

Stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Parameter expireTimeSpan: Lifetime
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.SetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<bool> SetAsync(string key, object value);

Asynchronously stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.SetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<bool> SetAsync(string key, object value, int expireSeconds);

Asynchronously stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Parameter expireSeconds: Lifetime in seconds
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.SetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<bool> SetAsync(string key, object value, TimeSpan expireTimeSpan);

Asynchronously stores a value under the specified cache key

  • Parameter key: Cache key
  • Parameter value: Value to cache
  • Parameter expireTimeSpan: Lifetime
  • Returns: Returns true when the cache write succeeds; otherwise false

Fast.Cache.ICache.GetAllKeys ​

Source · Targets: net8.0, net9.0, net10.0

csharp
List<string> GetAllKeys();

Gets all cache keys in the current Redis database

Remarks: Scans the database keys and can be expensive for large key sets. Do not call this on high-frequency request paths.

  • Returns: The collection of cache keys in the current Redis database

Fast.Cache.ICache.GetAllKeysAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<List<string>> GetAllKeysAsync();

Asynchronously gets all cache keys in the current Redis database

Remarks: Scans the database keys and can be expensive for large key sets. Do not call this on high-frequency request paths.

  • Returns: A task whose result is the collection of cache keys in the current Redis database

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string GetAndSet(string key, Func<string> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
T GetAndSet<T>(string key, Func<T> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Type parameter T: Type of the cached value
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string GetAndSet(string key, int expireSeconds, Func<string> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireSeconds: Lifetime in seconds
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
T GetAndSet<T>(string key, int expireSeconds, Func<T> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireSeconds: Lifetime in seconds
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Type parameter T: Type of the cached value
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
string GetAndSet(string key, TimeSpan expireTimeSpan, Func<string> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireTimeSpan: Lifetime
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSet ​

Source · Targets: net8.0, net9.0, net10.0

csharp
T GetAndSet<T>(string key, TimeSpan expireTimeSpan, Func<T> func);

Gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireTimeSpan: Lifetime
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Type parameter T: Type of the cached value
  • Returns: The cached value, or the new value created and stored by the factory on a cache miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<string> GetAndSetAsync(string key, Func<Task<string>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<T> GetAndSetAsync<T>(string key, Func<Task<T>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Type parameter T: Type of the cached value
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<string> GetAndSetAsync(string key, int expireSeconds, Func<Task<string>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireSeconds: Lifetime in seconds
  • Parameter func: Delegate that asynchronously creates a value when the cache entry is missing
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<T> GetAndSetAsync<T>(string key, int expireSeconds, Func<Task<T>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireSeconds: Lifetime in seconds
  • Parameter func: Delegate that asynchronously creates a value when the cache entry is missing
  • Type parameter T: Type of the cached value
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<string> GetAndSetAsync(string key, TimeSpan expireTimeSpan, Func<Task<string>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireTimeSpan: Lifetime
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.ICache.GetAndSetAsync ​

Source · Targets: net8.0, net9.0, net10.0

csharp
Task<T> GetAndSetAsync<T>(string key, TimeSpan expireTimeSpan, Func<Task<T>> func);

Asynchronously gets a cached value, or creates and stores a new value on a cache miss

  • Parameter key: Cache key
  • Parameter expireTimeSpan: Lifetime
  • Parameter func: Delegate that creates and stores a value on a cache miss
  • Type parameter T: Type of the cached value
  • Returns: A task whose result is the cached value or the value created and stored by the factory on a miss

Fast.Cache.RedisSettingsOptions ​

Source · Targets: net8.0, net9.0, net10.0

csharp
[SuppressSniffer]
public class RedisSettingsOptions : IPostConfigure

Redis connection string configuration

Fast.Cache.RedisSettingsOptions.ServiceIp ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public string ServiceIp { get; set; }

Server IP address

Fast.Cache.RedisSettingsOptions.Port ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public int? Port { get; set; }

Port number

Fast.Cache.RedisSettingsOptions.DbName ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public int? DbName { get; set; }

Default database

Fast.Cache.RedisSettingsOptions.DbPwd ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public string DbPwd { get; set; }

Password

Fast.Cache.RedisSettingsOptions.Prefix ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public string Prefix { get; set; }

Prefix

Fast.Cache.RedisSettingsOptions.Poolsize ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public int? Poolsize { get; set; }

Connection pool size

Fast.Cache.RedisSettingsOptions.SSL ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public bool? SSL { get; set; }

SSL encrypted connection

Fast.Cache.RedisSettingsOptions.Services ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public List<RedisServiceSettingsOptions> Services { get; set; }

Services

Fast.Cache.RedisSettingsOptions.PostConfigure ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public void PostConfigure()

Documentation is inherited from an interface or base class; consult that declaration.

Fast.Cache.RedisServiceSettingsOptions ​

Source · Targets: net8.0, net9.0, net10.0

csharp
[SuppressSniffer]
public class RedisServiceSettingsOptions : RedisSettingsOptions

Redis connection service configuration

Fast.Cache.RedisServiceSettingsOptions.ServiceName ​

Source · Targets: net8.0, net9.0, net10.0

csharp
public string ServiceName { get; set; }

Service name