using Senparc.CO2NET.Cache;
using Senparc.Weixin.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Senparc.Weixin.Cache
{
public abstract class BaseContainerCacheStrategy : IContainerCacheStrategy
{
#region IDomainExtensionCacheStrategy 成员
public abstract ICacheStrategyDomain CacheStrategyDomain { get; }
///
/// 数据源缓存策略
///
public Func BaseCacheStrategy { get; protected set; }
#endregion
#region IContainerCacheStrategy 成员
public abstract IDictionary GetAll() where TBag : IBaseContainerBag;
///
/// 获取单个ContainerBag
///
/// 缓存键
/// 是否已经是完整的Key,如果不是,则会调用一次GetFinalKey()方法
///
public virtual TBag GetContainerBag(string key, bool isFullKey = false) where TBag : IBaseContainerBag
{
var baseCacheStrategy = BaseCacheStrategy();
return baseCacheStrategy.Get(key, isFullKey);
}
///
/// 向底层缓存注册当前缓存策略
///
///
public void RegisterCacheStrategyDomain(IDomainExtensionCacheStrategy extensionCacheStrategy)
{
CacheStrategyDomainWarehouse.RegisterCacheStrategyDomain(extensionCacheStrategy);
}
public virtual void UpdateContainerBag(string key, IBaseContainerBag bag, TimeSpan? expiry = null, bool isFullKey = false)
{
var baseCacheStrategy = BaseCacheStrategy();
baseCacheStrategy.Update(key, bag, expiry, isFullKey);
}
#endregion
}
}