Skip to content

Commit

Permalink
Min the batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Cricle committed Dec 4, 2024
1 parent e7f582d commit 764cea7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 200 deletions.
2 changes: 1 addition & 1 deletion src/Ao.Cache.Core/CacheHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private Finders<TReturn> BuildFinders(Type instanceType, MethodInfo method)
{
declareAttr = instanceType.GetCustomAttribute<CacheProxyAttribute>();
}
var proxyAttr = method.GetCustomAttribute<CacheProxyMethodAttribute>();
var proxyAttr = method.GetCustomAttribute<CacheProxyMethodAttribute>();//TODO: 这里不用反射,而是直接传入
var finder = Factory.Create<string, TReturn>();
var syncFinder = SyncFactory.CreateSync<string, TReturn>();
string head = null;
Expand Down
34 changes: 0 additions & 34 deletions src/Ao.Cache.Core/DataFinders.cs

This file was deleted.

28 changes: 14 additions & 14 deletions src/Ao.Cache.Core/ICacheVisitor.Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ namespace Ao.Cache
{
public partial interface ICacheVisitor
{
IDictionary<string, bool> Exists(IReadOnlyList<string> keys);
long Exists(IReadOnlyList<string> keys);

Task<IDictionary<string, bool>> ExistsAsync(IReadOnlyList<string> keys);
Task<long> ExistsAsync(IReadOnlyList<string> keys);

IDictionary<string, T> Get<T>(IReadOnlyList<string> keys);
IReadOnlyList<T> Get<T>(IReadOnlyList<string> keys);

Task<IDictionary<string, T>> GetAsync<T>(IReadOnlyList<string> keys);
Task<IReadOnlyList<T>> GetAsync<T>(IReadOnlyList<string> keys);

IDictionary<string, bool> Set<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);
long Set<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);

Task<IDictionary<string, bool>> SetAsync<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);
Task<long> SetAsync<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);

IDictionary<string, string> GetString(IReadOnlyList<string> keys);
IReadOnlyList<string> GetString(IReadOnlyList<string> keys);

Task<IDictionary<string, string>> GetStringAsync(IReadOnlyList<string> keys);
Task<IReadOnlyList<string>> GetStringAsync(IReadOnlyList<string> keys);

IDictionary<string, bool> SetString(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);
long SetString(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);

Task<IDictionary<string, bool>> SetStringAsync(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);
Task<long> SetStringAsync(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always);

IDictionary<string, bool> Delete(IReadOnlyList<string> keys);
long Delete(IReadOnlyList<string> keys);

Task<IDictionary<string, bool>> DeleteAsync(IReadOnlyList<string> keys);
Task<long> DeleteAsync(IReadOnlyList<string> keys);

IDictionary<string, bool> Expire(IReadOnlyList<string> keys, TimeSpan? cacheTime);
long Expire(IReadOnlyList<string> keys, TimeSpan? cacheTime);

Task<IDictionary<string, bool>> ExpireAsync(IReadOnlyList<string> keys, TimeSpan? cacheTime);
Task<long> ExpireAsync(IReadOnlyList<string> keys, TimeSpan? cacheTime);
}
}
71 changes: 33 additions & 38 deletions src/Ao.Cache.InMemory/MemoryCacheVisitor.Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,114 +6,109 @@ namespace Ao.Cache.InMemory
{
public partial class MemoryCacheVisitor
{
public IDictionary<string, bool> Delete(IReadOnlyList<string> keys)
public long Delete(IReadOnlyList<string> keys)
{
var map = new Dictionary<string, bool>(keys.Count);
var res = 0;
for (int i = 0; i < keys.Count; i++)
{
var data = keys[i];
map[data] = Delete(data);
if (Delete(keys[i])) res++;
}
return map;
return res;
}

public Task<IDictionary<string, bool>> DeleteAsync(IReadOnlyList<string> keys)
public Task<long> DeleteAsync(IReadOnlyList<string> keys)
{
return Task.FromResult(Delete(keys));
}

public IDictionary<string, bool> Exists(IReadOnlyList<string> keys)
public long Exists(IReadOnlyList<string> keys)
{
var map = new Dictionary<string, bool>(keys.Count);
var res = 0;
for (int i = 0; i < keys.Count; i++)
{
var data = keys[i];
map[data] = Exists(data);
if (Exists(keys[i])) res++;
}
return map;
return res;
}

public Task<IDictionary<string, bool>> ExistsAsync(IReadOnlyList<string> keys)
public Task<long> ExistsAsync(IReadOnlyList<string> keys)
{
return Task.FromResult(Exists(keys));
}

public IDictionary<string, bool> Expire(IReadOnlyList<string> keys, TimeSpan? cacheTime)
public long Expire(IReadOnlyList<string> keys, TimeSpan? cacheTime)
{
var map = new Dictionary<string, bool>(keys.Count);
var res = 0;
for (int i = 0; i < keys.Count; i++)
{
var data = keys[i];
map[data] = Expire(data, cacheTime);
if (Expire(keys[i],cacheTime)) res++;
}
return map;
return res;
}

public Task<IDictionary<string, bool>> ExpireAsync(IReadOnlyList<string> keys, TimeSpan? cacheTime)
public Task<long> ExpireAsync(IReadOnlyList<string> keys, TimeSpan? cacheTime)
{
return Task.FromResult(Expire(keys, cacheTime));
}

public IDictionary<string, T> Get<T>(IReadOnlyList<string> keys)
public IReadOnlyList<T> Get<T>(IReadOnlyList<string> keys)
{
var map = new Dictionary<string, T>(keys.Count);
var map = new T[keys.Count];
for (int i = 0; i < keys.Count; i++)
{
var data = keys[i];
map[data] = Get<T>(data);
map[i] = Get<T>(keys[i]);
}
return map;
}

public Task<IDictionary<string, T>> GetAsync<T>(IReadOnlyList<string> keys)
public Task<IReadOnlyList<T>> GetAsync<T>(IReadOnlyList<string> keys)
{
return Task.FromResult(Get<T>(keys));
}

public IDictionary<string, string> GetString(IReadOnlyList<string> keys)
public IReadOnlyList<string> GetString(IReadOnlyList<string> keys)
{
var map = new Dictionary<string, string>(keys.Count);
var map = new string[keys.Count];
for (int i = 0; i < keys.Count; i++)
{
var data = keys[i];
map[data] = GetString(data);
map[i] = GetString(keys[i]);
}
return map;
}

public Task<IDictionary<string, string>> GetStringAsync(IReadOnlyList<string> keys)
public Task<IReadOnlyList<string>> GetStringAsync(IReadOnlyList<string> keys)
{
return Task.FromResult(GetString(keys));
}

public IDictionary<string, bool> Set<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
public long Set<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
{
var map = new Dictionary<string, bool>(datas.Length);
var res = 0;
for (int i = 0; i < datas.Length; i++)
{
var data = datas[i];
map[data.Key] = Set(data.Key, data.Value, cacheTime, cacheSetIf);
if (Set(data.Key, data.Value, cacheTime, cacheSetIf)) res++;
}
return map;
return res;
}

public Task<IDictionary<string, bool>> SetAsync<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
public Task<long> SetAsync<T>(KeyValuePair<string, T>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
{
return Task.FromResult(Set(datas, cacheTime, cacheSetIf));
}

public IDictionary<string, bool> SetString(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
public long SetString(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
{
var map = new Dictionary<string, bool>(datas.Length);
var res = 0;
for (int i = 0; i < datas.Length; i++)
{
var data = datas[i];
map[data.Key] = SetString(data.Key, data.Value, cacheTime, cacheSetIf);
if (SetString(data.Key, data.Value, cacheTime, cacheSetIf)) res++;
}
return map;
return res;
}

public Task<IDictionary<string, bool>> SetStringAsync(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
public Task<long> SetStringAsync(KeyValuePair<string, string>[] datas, TimeSpan? cacheTime, CacheSetIf cacheSetIf = CacheSetIf.Always)
{
return Task.FromResult(SetString(datas, cacheTime, cacheSetIf));
}
Expand Down
Loading

0 comments on commit 764cea7

Please sign in to comment.