예제 #1
0
 public void Set <TService>(
     CachedServiceBase <TService> cached,
     CacheParams par,
     Action <CachedServiceBase <TService> > setData)
     where TService : class
 {
     setData(cached);
     Invalidate(par);
 }
예제 #2
0
        public async Task SetAsync <TService>(
            CachedServiceBase <TService> cached,
            CacheParams par,
            Func <CachedServiceBase <TService>, Task> setData)
            where TService : class
        {
            await setData(cached);

            Invalidate(par);
        }
예제 #3
0
 public void Set <TService, TResult>(
     CachedServiceBase <TService> cached,
     CacheParams par,
     TResult value,
     Action <CachedServiceBase <TService>, TResult> setData)
     where TService : class
 {
     setData(cached, value);
     Save(par, value);
 }
예제 #4
0
        public async Task SetAsync <TService, TResult>(
            CachedServiceBase <TService> cached,
            CacheParams par,
            TResult value,
            Func <CachedServiceBase <TService>, TResult, Task> setData)
            where TService : class
        {
            await setData(cached, value);

            Save(par, value);
        }
예제 #5
0
 public void Set <TService>(
     CachedServiceBase <TService> cached,
     CacheParams par,
     Action <CachedServiceBase <TService> > setData)
     where TService : class
 => memoryCache.Set(cached, par, service =>
 {
     setData(service);
     if (this is IRemoteCache remote0)
     {
         remote0.Invalidate(par);
     }
     else if (this is IRemoteCacheAsync remoteAsync0)
     {
         Task task = remoteAsync0.InvalidateAsync(par);
         task.Wait();
     }
 });
예제 #6
0
 public void Set <TService, TResult>(
     CachedServiceBase <TService> cached,
     CacheParams par,
     TResult value,
     Action <CachedServiceBase <TService>, TResult> setData)
     where TService : class
 => memoryCache.Set(cached, par, value, (service, value) =>
 {
     setData(service, value);
     if (this is IRemoteCache remote0)
     {
         remote0.Save(par, value);
     }
     else if (this is IRemoteCacheAsync remoteAsync0)
     {
         Task task = remoteAsync0.SaveAsync(par, value);
         task.Wait();
     }
 });
예제 #7
0
        public TResult Get <TService, TResult>(
            CachedServiceBase <TService> cached,
            CacheParams par,
            Func <CachedServiceBase <TService>, TResult> getData)
            where TService : class
        => memoryCache.Get(cached, par, service =>
        {
            TResult data = default;
            if (this is IRemoteCache remote)
            {
                if (remote.Contains(par.Key))
                {
                    data = remote.Load <TResult>(par);
                    return(data);
                }
            }
            else if (this is IRemoteCacheAsync remoteAsync)
            {
                if (remoteAsync.Contains(par.Key))
                {
                    Task <TResult> task = remoteAsync.LoadAsync <TResult>(par);
                    task.Wait();
                    data = task.Result;
                    return(data);
                }
            }
            else
            {
                throw new InvalidOperationException($"Manager {GetType().FullName} has is not implemented.");
            }

            data = getData(cached);
            if (this is IRemoteCache remote0)
            {
                remote0.Save(par, data);
            }
            else if (this is IRemoteCacheAsync remoteAsync0)
            {
                Task task = remoteAsync0.SaveAsync(par, data);
                task.Wait();
            }
            return(data);
        });
예제 #8
0
        public async Task <TResult> GetAsync <TService, TResult>(
            CachedServiceBase <TService> cached,
            CacheParams par,
            Func <CachedServiceBase <TService>, Task <TResult> > getData)
            where TService : class
        {
            if (localCache.ContainsKey(par.Key))
            {
                lock (cacheLock)
                    if (localCache.ContainsKey(par.Key))
                    {
                        CachedObject item = localCache[par.Key] as CachedObject;
                        if (!item.IsExpired)
                        {
                            return((TResult)item.Data);
                        }
                    }
            }
            TResult data = await getData(cached);

            Save(par, data);
            return(data);
        }
예제 #9
0
 public async Task <TResult> GetAsync <TService, TResult>(
     CachedServiceBase <TService> cached,
     CacheParams par,
     Func <CachedServiceBase <TService>, Task <TResult> > getData)
     where TService : class
 => await memoryCache.GetAsync(cached, par, async service =>