Browse Source

Improve clear cache

pull/19380/head
Salih 3 years ago
parent
commit
7ac072de0c
  1. 6
      modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs
  2. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs
  3. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs
  4. 5
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs
  5. 10
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

6
modules/docs/src/Volo.Docs.Admin.Application/Volo/Docs/Admin/Documents/DocumentAdminAppService.cs

@ -57,7 +57,7 @@ namespace Volo.Docs.Admin.Documents
var versionCacheKey = CacheKeyGenerator.GenerateProjectVersionsCacheKey(project);
await _versionCache.RemoveAsync(versionCacheKey, true);
var documents = await _documentRepository.GetListByProjectId(project.Id);
var documents = await _documentRepository.GetListWithoutDetailsByProjectId(project.Id);
var documentUpdateInfoCacheKeys = documents.Select(document =>
CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey(
@ -69,10 +69,8 @@ namespace Volo.Docs.Admin.Documents
);
await _documentUpdateCache.RemoveManyAsync(documentUpdateInfoCacheKeys);
documents.ForEach(document => document.LastCachedTime = DateTime.MinValue);
await _documentRepository.UpdateManyAsync(documents);
await _documentRepository.ClearCachesAsync(project.Id);
}
public virtual async Task PullAllAsync(PullAllDocumentInput input)

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/DocumentWithoutDetails.cs

@ -5,6 +5,8 @@ namespace Volo.Docs.Documents
public class DocumentWithoutDetails
{
public Guid Id { get; set; }
public string Name { get; set; }
public virtual string Version { get; set; }

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentRepository.cs

@ -12,6 +12,8 @@ namespace Volo.Docs.Documents
Task<List<DocumentInfo>> GetUniqueListDocumentInfoAsync(CancellationToken cancellationToken = default);
Task<List<Document>> GetListByProjectId(Guid projectId, CancellationToken cancellationToken = default);
Task ClearCachesAsync(Guid projectId, CancellationToken cancellationToken = default);
Task<Document> FindAsync(Guid projectId,
string name,

5
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Documents/EFCoreDocumentRepository.cs

@ -55,6 +55,11 @@ namespace Volo.Docs.Documents
return await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task ClearCachesAsync(Guid projectId, CancellationToken cancellationToken = default)
{
await (await GetDbSetAsync()).Where(d => d.ProjectId == projectId).ExecuteUpdateAsync(x => x.SetProperty(d => d.LastCachedTime, DateTime.MinValue), GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Document>> GetListAsync(Guid? projectId, string version, string name, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())

10
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Documents/MongoDocumentRepository.cs

@ -53,6 +53,16 @@ namespace Volo.Docs.Documents
return await (await GetMongoQueryableAsync(cancellationToken)).Where(d => d.ProjectId == projectId).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task ClearCachesAsync(Guid projectId, CancellationToken cancellationToken = default)
{
var collection = await GetCollectionAsync(cancellationToken);
await collection.UpdateManyAsync(
Builders<Document>.Filter.Eq(x => x.ProjectId, projectId),
Builders<Document>.Update.Set(x => x.LastCachedTime, DateTime.MinValue),
cancellationToken: GetCancellationToken(cancellationToken)
);
}
public virtual async Task<Document> FindAsync(Guid projectId, string name, string languageCode, string version,
bool includeDetails = true,
CancellationToken cancellationToken = default)

Loading…
Cancel
Save