|
|
@ -1,5 +1,8 @@ |
|
|
|
|
|
using System; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
using Volo.Abp.Application.Services; |
|
|
using Volo.Abp.Application.Services; |
|
|
|
|
|
using Volo.Abp.Caching; |
|
|
using Volo.Docs.Projects; |
|
|
using Volo.Docs.Projects; |
|
|
|
|
|
|
|
|
namespace Volo.Docs.Documents |
|
|
namespace Volo.Docs.Documents |
|
|
@ -8,13 +11,19 @@ namespace Volo.Docs.Documents |
|
|
{ |
|
|
{ |
|
|
private readonly IProjectRepository _projectRepository; |
|
|
private readonly IProjectRepository _projectRepository; |
|
|
private readonly IDocumentStoreFactory _documentStoreFactory; |
|
|
private readonly IDocumentStoreFactory _documentStoreFactory; |
|
|
|
|
|
protected IDistributedCache<DocumentWithDetailsDto> DocumentCache { get; } |
|
|
|
|
|
protected IDistributedCache<DocumentResourceDto> ResourceCache { get; } |
|
|
|
|
|
|
|
|
public DocumentAppService( |
|
|
public DocumentAppService( |
|
|
IProjectRepository projectRepository, |
|
|
IProjectRepository projectRepository, |
|
|
IDocumentStoreFactory documentStoreFactory) |
|
|
IDocumentStoreFactory documentStoreFactory, |
|
|
|
|
|
IDistributedCache<DocumentWithDetailsDto> documentCache, |
|
|
|
|
|
IDistributedCache<DocumentResourceDto> resourceCache) |
|
|
{ |
|
|
{ |
|
|
_projectRepository = projectRepository; |
|
|
_projectRepository = projectRepository; |
|
|
_documentStoreFactory = documentStoreFactory; |
|
|
_documentStoreFactory = documentStoreFactory; |
|
|
|
|
|
DocumentCache = documentCache; |
|
|
|
|
|
ResourceCache = resourceCache; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input) |
|
|
public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input) |
|
|
@ -53,11 +62,22 @@ namespace Volo.Docs.Documents |
|
|
public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input) |
|
|
public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input) |
|
|
{ |
|
|
{ |
|
|
var project = await _projectRepository.GetAsync(input.ProjectId); |
|
|
var project = await _projectRepository.GetAsync(input.ProjectId); |
|
|
var store = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var cacheKey = $"Resource@{project.ShortName}#{input.Name}#{input.Version}"; |
|
|
|
|
|
|
|
|
var documentResource = await store.GetResource(project, input.Name, input.Version); |
|
|
return await ResourceCache.GetOrAddAsync( |
|
|
|
|
|
cacheKey, |
|
|
|
|
|
async () => |
|
|
|
|
|
{ |
|
|
|
|
|
var store = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
|
|
|
var documentResource = await store.GetResource(project, input.Name, input.Version); |
|
|
|
|
|
|
|
|
return ObjectMapper.Map<DocumentResource, DocumentResourceDto>(documentResource); |
|
|
return ObjectMapper.Map<DocumentResource, DocumentResourceDto>(documentResource); |
|
|
|
|
|
}, |
|
|
|
|
|
() => new DistributedCacheEntryOptions |
|
|
|
|
|
{ |
|
|
|
|
|
SlidingExpiration = TimeSpan.FromMinutes(30) //TODO: Configurable?
|
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDto( |
|
|
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDto( |
|
|
@ -65,10 +85,22 @@ namespace Volo.Docs.Documents |
|
|
string documentName, |
|
|
string documentName, |
|
|
string version) |
|
|
string version) |
|
|
{ |
|
|
{ |
|
|
var store = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var cacheKey = $"Document@{project.ShortName}#{documentName}#{version}"; |
|
|
var document = await store.GetDocument(project, documentName, version); |
|
|
|
|
|
|
|
|
return await DocumentCache.GetOrAddAsync( |
|
|
|
|
|
cacheKey, |
|
|
|
|
|
async () => |
|
|
|
|
|
{ |
|
|
|
|
|
var store = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
|
|
|
var document = await store.GetDocument(project, documentName, version); |
|
|
|
|
|
|
|
|
return CreateDocumentWithDetailsDto(project, document); |
|
|
return CreateDocumentWithDetailsDto(project, document); |
|
|
|
|
|
}, |
|
|
|
|
|
() => new DistributedCacheEntryOptions |
|
|
|
|
|
{ |
|
|
|
|
|
SlidingExpiration = TimeSpan.FromMinutes(30) //TODO: Configurable?
|
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual DocumentWithDetailsDto CreateDocumentWithDetailsDto(Project project, Document document) |
|
|
protected virtual DocumentWithDetailsDto CreateDocumentWithDetailsDto(Project project, Document document) |
|
|
|