Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

CacheKeyManager.cs

using Nop.Core.Infrastructure;

namespace Nop.Core.Caching;

/// 
/// Cache key manager
/// 
/// 
/// This class should be registered on IoC as singleton instance
/// 
public partial class CacheKeyManager : ICacheKeyManager
{
    protected readonly IConcurrentCollection _keys;

    public CacheKeyManager(IConcurrentCollection keys)
    {
        _keys = keys;
    }

    /// 
    /// Add the key
    /// 
    /// The key to add
    public void AddKey(string key)
    {
        _keys.Add(key, default);
    }

    /// 
    /// Remove the key
    /// 
    /// The key to remove
    public void RemoveKey(string key)
    {
        _keys.Remove(key);
    }

    /// 
    /// Remove all keys
    /// 
    public void Clear()
    {
        _keys.Clear();
    }

    /// 
    /// Remove keys by prefix
    /// 
    /// Prefix to delete keys
    /// The list of removed keys
    public IEnumerable RemoveByPrefix(string prefix)
    {
        if (!_keys.Prune(prefix, out var subtree) || subtree?.Keys == null)
            return Enumerable.Empty();

        return subtree.Keys;
    }

    /// 
    /// The list of keys
    /// 
    public IEnumerable Keys => _keys.Keys;
}