public Person Get(int id)
        {
            string personId = $"person{id}";

            if (_cacheAdapter.Exists(personId))
            {
                return(_cacheAdapter.Get <Person>(personId));
            }
            Person person = _personRepository.Get(id);

            _cacheAdapter.Add(personId, person);
            return(person);
        }
Пример #2
0
 /// <summary>
 /// 是否存在缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <returns>是否存在</returns>
 public static bool Exists(string key)
 {
     using (ICacheAdapter cacheAdapter = (ICacheAdapter)Activator.CreateInstance(_CacheImplType))
     {
         lock (_Sync)
         {
             return(cacheAdapter.Exists(key));
         }
     }
 }