Browse Source

Added other methods for distributed cache

pull/216/head
Halil İbrahim Kalkan 9 years ago
parent
commit
d2bb080806
  1. 49
      src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
  2. 23
      src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs

49
src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs

@ -24,9 +24,18 @@ namespace Volo.Abp.Caching
ObjectSerializer = objectSerializer;
}
public async Task<TCacheItem> GetAsync(
string key,
CancellationToken token = default)
public TCacheItem Get(string key)
{
var cachedBytes = Cache.Get(key);
if (cachedBytes == null)
{
return null;
}
return ObjectSerializer.Deserialize<TCacheItem>(cachedBytes);
}
public async Task<TCacheItem> GetAsync(string key, CancellationToken token = default)
{
var cachedBytes = await Cache.GetAsync(key, CancellationTokenProvider.FallbackToProvider(token));
if (cachedBytes == null)
@ -37,11 +46,16 @@ namespace Volo.Abp.Caching
return ObjectSerializer.Deserialize<TCacheItem>(cachedBytes);
}
public Task SetAsync(
string key,
TCacheItem value,
DistributedCacheEntryOptions options = null,
CancellationToken token = default)
public void Set(string key, TCacheItem value, DistributedCacheEntryOptions options)
{
Cache.Set(
key,
ObjectSerializer.Serialize(value),
options ?? new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(20) } //TODO: implement per cache item and global defaults!!!
);
}
public Task SetAsync(string key, TCacheItem value, DistributedCacheEntryOptions options = null, CancellationToken token = default)
{
return Cache.SetAsync(
key,
@ -51,9 +65,22 @@ namespace Volo.Abp.Caching
);
}
public Task RemoveAsync(
string key,
CancellationToken token = default)
public void Refresh(string key)
{
Cache.Refresh(key);
}
public Task RefreshAsync(string key, CancellationToken token = default)
{
return Cache.RefreshAsync(key, CancellationTokenProvider.FallbackToProvider(token));
}
public void Remove(string key)
{
Cache.Remove(key);
}
public Task RemoveAsync(string key, CancellationToken token = default)
{
return Cache.RemoveAsync(key, CancellationTokenProvider.FallbackToProvider(token));
}

23
src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs

@ -8,11 +8,21 @@ namespace Volo.Abp.Caching
public interface IDistributedCache<TCacheItem>
where TCacheItem : class
{
TCacheItem Get(
string key
);
Task<TCacheItem> GetAsync(
[NotNull] string key,
CancellationToken token = default
);
void Set(
string key,
TCacheItem value,
DistributedCacheEntryOptions options
);
Task SetAsync(
[NotNull] string key,
[NotNull] TCacheItem value,
@ -20,6 +30,19 @@ namespace Volo.Abp.Caching
CancellationToken token = default
);
void Refresh(
string key
);
Task RefreshAsync(
string key,
CancellationToken token = default
);
void Remove(
string key
);
Task RemoveAsync(
string key,
CancellationToken token = default

Loading…
Cancel
Save