Skip to content

Commit 63ebb87

Browse files
committed
Resolves smartstore#2053: Handle output cache invalidation for media files
1 parent 230a10b commit 63ebb87

12 files changed

Lines changed: 74 additions & 33 deletions

File tree

src/Libraries/SmartStore.Core/Caching/OutputCache/DisplayControl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using SmartStore.Core.Domain.Catalog;
99
using SmartStore.Core.Domain.Discounts;
1010
using SmartStore.Core.Domain.Localization;
11+
using SmartStore.Core.Domain.Media;
1112
using SmartStore.Core.Domain.News;
1213
using SmartStore.Core.Domain.Topics;
1314
using SmartStore.Utilities;
@@ -36,6 +37,7 @@ public partial class DisplayControl : IDisplayControl
3637
[typeof(NewsItem)] = (x, c) => new[] { "n" + x.Id },
3738
[typeof(NewsComment)] = (x, c) => new[] { "n" + ((NewsComment)x).NewsItemId },
3839
[typeof(Topic)] = (x, c) => new[] { "t" + x.Id },
40+
[typeof(MediaFile)] = (x, c) => new[] { "mf" + x.Id },
3941
[typeof(SpecificationAttributeOption)] = (x, c) => ((SpecificationAttributeOption)x).ProductSpecificationAttributes.Select(y => "p" + y.ProductId),
4042
[typeof(ProductTag)] = (x, c) => ((ProductTag)x).Products.Select(y => "p" + y.Id),
4143
[typeof(Product)] = HandleProduct,
@@ -153,6 +155,9 @@ private static IEnumerable<string> HandleLocalizedProperty(BaseEntity entity, IC
153155
case nameof(Topic):
154156
prefix = "t";
155157
break;
158+
case nameof(MediaFile):
159+
prefix = "mf";
160+
break;
156161
case nameof(SpecificationAttribute):
157162
targetEntity = dbContext.Set<SpecificationAttribute>().Find(lp.EntityId);
158163
break;

src/Libraries/SmartStore.Core/Domain/Media/MediaFile.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ namespace SmartStore.Core.Domain.Media
1010
[DataContract]
1111
public partial class MediaFile : BaseEntity, ITransient, IHasMedia, IAuditable, ISoftDeletable, ILocalizedEntity
1212
{
13+
#region static
14+
15+
private static readonly HashSet<string> _outputAffectingProductProps = new HashSet<string>
16+
{
17+
nameof(MediaFile.FolderId),
18+
nameof(MediaFile.Name),
19+
nameof(MediaFile.Alt),
20+
nameof(MediaFile.Title),
21+
nameof(MediaFile.Hidden),
22+
nameof(MediaFile.Deleted)
23+
};
24+
25+
public static IReadOnlyCollection<string> GetOutputAffectingPropertyNames()
26+
{
27+
return _outputAffectingProductProps;
28+
}
29+
30+
#endregion
31+
1332
private ICollection<ProductMediaFile> _productMediaFiles;
1433
private ICollection<MediaTag> _tags;
1534
private ICollection<MediaTrack> _tracks;

src/Presentation/SmartStore.Web/Controllers/BlogController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ protected PictureModel PrepareBlogPostPictureModel(BlogPost blogPost, int? fileI
117117
AlternateText = file?.File?.GetLocalized(x => x.Alt)?.Value.NullEmpty() ?? blogPost.Title,
118118
File = file
119119
};
120+
121+
_services.DisplayControl.Announce(file?.File);
120122

121123
return pictureModel;
122124
}

src/Presentation/SmartStore.Web/Controllers/CatalogHelper.MapProduct.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ private void MapProductSummaryItem(Product product, MapProductSummaryItemContext
465465
AlternateText = file?.File?.GetLocalized(x => x.Alt)?.Value.NullEmpty() ?? string.Format(ctx.Resources["Media.Product.ImageAlternateTextFormat"], item.Name),
466466
File = file
467467
};
468+
469+
_services.DisplayControl.Announce(file?.File);
468470
}
469471

470472
// Manufacturers

src/Presentation/SmartStore.Web/Controllers/CatalogHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ public IList<CategorySummaryModel> MapCategorySummaryModel(IEnumerable<Category>
217217
File = file
218218
};
219219

220-
return model;
220+
_services.DisplayControl.Announce(file?.File);
221+
222+
return model;
221223
})
222224
.ToList();
223225
}
@@ -590,6 +592,8 @@ private PictureModel CreatePictureModel(ProductDetailsPictureModel model, MediaF
590592
File = _mediaService.ConvertMediaFile(file)
591593
};
592594

595+
_services.DisplayControl.Announce(file);
596+
593597
return result;
594598
}
595599

@@ -1508,7 +1512,9 @@ public PictureModel PrepareManufacturerPictureModel(
15081512
File = file
15091513
};
15101514

1511-
return model;
1515+
_services.DisplayControl.Announce(file?.File);
1516+
1517+
return model;
15121518
}
15131519

15141520
public ManufacturerNavigationModel PrepareManufacturerNavigationModel(int manufacturerItemsToDisplay)

src/Presentation/SmartStore.Web/Controllers/NewsController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ protected PictureModel PrepareNewsItemPictureModel(NewsItem newsItem, int? fileI
387387
File = file
388388
};
389389

390+
_services.DisplayControl.Announce(file?.File);
391+
390392
return pictureModel;
391393
}
392394

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
@using SmartStore.Web.Framework.Modelling;
2-
@model MediaTemplateModel
1+
@model MediaTemplateModel
2+
3+
@using SmartStore.Web.Framework.Modelling;
4+
35
@if (Model.RenderViewer)
46
{
57
<div class="w-100 embed-responsive embed-responsive-16by9 file-preview-container">
@@ -8,5 +10,5 @@
810
}
911
else
1012
{
11-
@Html.Partial("MediaTemplates/_Thumbnail")
13+
@Html.Partial("MediaTemplates/_Thumbnail", Model)
1214
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
@using SmartStore.Web.Framework.Modelling;
2-
@model MediaTemplateModel
3-
@if (Model.RenderViewer)
1+
@model MediaTemplateModel
2+
3+
@using SmartStore.Web.Framework.Modelling;
4+
5+
@if (!Model.RenderViewer)
46
{
5-
}
6-
else
7-
{
8-
@Html.Partial("MediaTemplates/_Thumbnail")
7+
@Html.Partial("MediaTemplates/_Thumbnail", Model)
98
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
@using SmartStore.Web.Framework.Modelling;
2-
@model MediaTemplateModel
3-
@if (Model.RenderViewer)
1+
@model MediaTemplateModel
2+
3+
@using SmartStore.Web.Framework.Modelling;
4+
5+
@if (!Model.RenderViewer)
46
{
5-
}
6-
else
7-
{
8-
@Html.Partial("MediaTemplates/_Thumbnail")
7+
@Html.Partial("MediaTemplates/_Thumbnail", Model)
98
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
@using SmartStore.Web.Framework.Modelling;
2-
@model MediaTemplateModel
3-
@if (Model.RenderViewer)
1+
@model MediaTemplateModel
2+
3+
@using SmartStore.Web.Framework.Modelling;
4+
5+
@if (!Model.RenderViewer)
46
{
5-
}
6-
else
7-
{
8-
@Html.Partial("MediaTemplates/_Thumbnail")
7+
@Html.Partial("MediaTemplates/_Thumbnail", Model)
98
}

0 commit comments

Comments
 (0)