mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Caching media profile queries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
@@ -8,10 +9,15 @@ using Orchard.MediaProcessing.Models;
|
||||
namespace Orchard.MediaProcessing.Services {
|
||||
public class ImageProfileService : IImageProfileService {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
private readonly IRepository<FilterRecord> _filterRepository;
|
||||
|
||||
public ImageProfileService(IContentManager contentManager, IRepository<FilterRecord> filterRepository) {
|
||||
public ImageProfileService(
|
||||
IContentManager contentManager,
|
||||
ICacheManager cacheManager,
|
||||
IRepository<FilterRecord> filterRepository) {
|
||||
_contentManager = contentManager;
|
||||
_cacheManager = cacheManager;
|
||||
_filterRepository = filterRepository;
|
||||
}
|
||||
|
||||
@@ -22,7 +28,25 @@ namespace Orchard.MediaProcessing.Services {
|
||||
}
|
||||
|
||||
public ImageProfilePart GetImageProfileByName(string name) {
|
||||
return _contentManager.Query<ImageProfilePart, ImageProfilePartRecord>().Where(x => x.Name == name).Slice(0, 1).FirstOrDefault();
|
||||
|
||||
var profileId = _cacheManager.Get("ProfileId", ctx => {
|
||||
var profile = _contentManager.Query<ImageProfilePart, ImageProfilePartRecord>()
|
||||
.Where(x => x.Name == name)
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (profile == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return profile.Id;
|
||||
});
|
||||
|
||||
if (profileId == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _contentManager.Get<ImageProfilePart>(profileId);
|
||||
}
|
||||
|
||||
public IEnumerable<ImageProfilePart> GetAllImageProfiles() {
|
||||
|
Reference in New Issue
Block a user