Docs module cache clear: refactor & simplify

pull/3680/head
Yunus Emre Kalkan 5 years ago
parent c05eb0ecf1
commit e2ddaaa561

@ -54,31 +54,20 @@ namespace Volo.Docs.Admin.Documents
var project = await _projectRepository.GetAsync(input.ProjectId); var project = await _projectRepository.GetAsync(input.ProjectId);
var languageCacheKey = CacheKeyGenerator.GenerateProjectLanguageCacheKey(project); var languageCacheKey = CacheKeyGenerator.GenerateProjectLanguageCacheKey(project);
var languageConfig = await _languageCache.GetAsync(languageCacheKey, true); await _languageCache.RemoveAsync(languageCacheKey, true);
CheckNotNullCacheValue(languageConfig);
var versionCacheKey = CacheKeyGenerator.GenerateProjectVersionsCacheKey(project); var versionCacheKey = CacheKeyGenerator.GenerateProjectVersionsCacheKey(project);
var versions = await _versionCache.GetAsync(versionCacheKey, true);
CheckNotNullCacheValue(versions);
await _languageCache.RemoveAsync(languageCacheKey, true);
await _versionCache.RemoveAsync(versionCacheKey, true); await _versionCache.RemoveAsync(versionCacheKey, true);
var documents = await _documentRepository.GetListByProjectId(project.Id); var documents = await _documentRepository.GetListByProjectId(project.Id);
foreach (var languageCode in languageConfig.Languages) foreach (var document in documents)
{ {
foreach (var version in versions) var documentUpdateInfoCacheKey = CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey(project, document.Name, document.LanguageCode, document.LanguageCode);
{ await _documentUpdateCache.RemoveAsync(documentUpdateInfoCacheKey);
foreach (var document in documents)
{ document.LastCachedTime = DateTime.MinValue;
var documentUpdateInfoCacheKey = CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey(project, document.Name, languageCode.Code, version.Name); await _documentRepository.UpdateAsync(document);
await _documentUpdateCache.RemoveAsync(documentUpdateInfoCacheKey);
document.LastCachedTime = DateTime.MinValue;
await _documentRepository.UpdateAsync(document);
}
}
} }
} }
@ -162,14 +151,6 @@ namespace Volo.Docs.Admin.Documents
} }
} }
private void CheckNotNullCacheValue(object cacheValue)
{
if (cacheValue == null)
{
throw new UserFriendlyException(L["CacheNullExceptionMessage"]);
}
}
private async Task UpdateDocumentUpdateInfoCache(Document document) private async Task UpdateDocumentUpdateInfoCache(Document document)
{ {
var cacheKey = $"DocumentUpdateInfo{document.ProjectId}#{document.Name}#{document.LanguageCode}#{document.Version}"; var cacheKey = $"DocumentUpdateInfo{document.ProjectId}#{document.Name}#{document.LanguageCode}#{document.Version}";

Loading…
Cancel
Save