Skip to content

Commit

Permalink
新增测试缓存拦截
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhll committed Jul 22, 2023
1 parent b5618b9 commit 38202c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 8 additions & 0 deletions framework/test/IAnotherApplication/IAnotherAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public interface IAnotherAppService
[GetCachingIntercept("Query1:id{id}:code:{code}")]
Task<string> Query1(long id, long? code);

[HttpPut("update/{id:long}")]
[UpdateCachingIntercept("Query1:id{id}:code:{code}")]
Task<string> Update(long id, long? code);

[HttpDelete("delete/{id:long}")]
[RemoveMatchKeyCachingIntercept(typeof(string), "Query1:id{id}:code:*")]
Task<string> Delete(long id);

Task ReturnNullTest();
}
}
16 changes: 9 additions & 7 deletions framework/test/TestApplication/AppService/TestAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public async Task<TestOut> Get(long id)
{
throw new UserFriendlyException($"不存在Id为{id}的数据");
}

return test.Adapt<TestOut>();
}

Expand Down Expand Up @@ -97,18 +98,19 @@ public async Task<string> DeleteAsync(long id)
{
throw new UserFriendlyException($"不存在Id为{id}的数据");
}

await _testRepository.DeleteAsync(entity);
await _distributedCache.RemoveAsync($"name:{entity.Name}");
return "删除数据成功";
}

public async Task<PagedList<TestOut>> Search1(string name, string address, IList<long> ids, int pageIndex = 1, int pageSize = 10)
public async Task<PagedList<TestOut>> Search1(string name, string address, IList<long> ids, int pageIndex = 1,
int pageSize = 10)
{
return await _testRepository.AsQueryable(false)
.Where(!name.IsNullOrEmpty(), p => p.Name.Contains(name))
.Where(!address.IsNullOrEmpty(), p => p.Address.Contains(name))
.Where(!ids.IsNullOrEmpty(),p=> ids.Contains(p.Id))
.Where(!ids.IsNullOrEmpty(), p => ids.Contains(p.Id))
.ProjectToType<TestOut>()
.ToPagedListAsync(pageIndex, pageSize);
}
Expand All @@ -118,13 +120,13 @@ public async Task<PagedList<TestOut>> Search2(SearchInput query)
return await _testRepository.AsQueryable(false)
.Where(!query.Name.IsNullOrEmpty(), p => p.Name.Contains(query.Name))
.Where(!query.Address.IsNullOrEmpty(), p => p.Address.Contains(query.Address))
.Where(!query.Ids.IsNullOrEmpty(),p=> query.Ids.Contains(p.Id))
.Where(!query.Ids.IsNullOrEmpty(), p => query.Ids.Contains(p.Id))
.ProjectToType<TestOut>()
.SortBy("Name-Asc")
.ToPagedListAsync(query.PageIndex, query.PageSize);
}

public Task<PagedList<TestOut>> Search3(long[] Ids,Sort[] sorts)
public Task<PagedList<TestOut>> Search3(long[] Ids, Sort[] sorts)
{
throw new System.NotImplementedException();
}
Expand Down Expand Up @@ -210,8 +212,8 @@ public async Task<IList<object>> GetObjectList()

public async Task<string> InvokeQuery1()
{
var result = await _invokeTemplate.GetForObjectAsync<string>("/api/another/query1/{id:long}", 1,2);
return result;
var result = await _invokeTemplate.GetForObjectAsync<string>("/api/another/query1/{id:long}", 1, 2);
return result;
}

public async Task<object> GetObject()
Expand Down
10 changes: 10 additions & 0 deletions framework/test/WsHostDemo/AppService/AnotherAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public async Task<string> Query1(long id, long? code)
return id.ToString() + code ?? "";
}

public async Task<string> Update(long id, long? code)
{
return id.ToString() + code ?? "";
}

public async Task<string> Delete(long id)
{
return id.ToString();
}

public Task ReturnNullTest()
{
return Task.CompletedTask;
Expand Down

0 comments on commit 38202c0

Please sign in to comment.