Sorry this is like half an answer but hoping it's something you or somebody else can pursue in finding the full answer for.
So I have a class file called ImageProcessing.cs which attaches events to the ValidatingRequest and OnPostProcessing event handlers of ImageProcessingModule. My plan was to store a flag in the HttpContext Items in the ValidatingRequest event containing the original URL of the image (if the nocache querystring is found), and delete the file in the OnPostProcessing event using the CachedImagePath variable of PostProcessingEventArgs which is the absolute path to the newly cached image.
Unfortunately CachedImagePath is no longer part of PostProcessingEventArgs & the documentation (https://imageprocessor.org/imageprocessor-web/imageprocessingmodule/) is out of date and unable to find an alternative.
Here's what I've started, good luck to anybody who finds a solution:
public class SubscribeToContentServiceSavingComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<SubscribeToContentServiceSavingComponent>();
}
}
public class SubscribeToContentServiceSavingComponent : Umbraco.Core.Composing.IComponent
{
public void Initialize()
{
ImageProcessingModule.ValidatingRequest += (sender, args) =>
{
var queryString = HttpUtility.ParseQueryString(args.QueryString);
if (queryString["nocache"] != null)
{
args.Context.Items.Add($"DeleteFromCache-{args.Context.Request.Url.AbsolutePath}", true);
}
};
ImageProcessingModule.OnPostProcessing += (sender, args) =>
{
//PostProcessingEventArgs
if (args.Context.Items[$"DeleteFromCache-{args.Context.Request.Url.AbsolutePath}"] != null)
{
System.IO.File.Delete(args.CachedImagePath)
}
};
}
}
ImageProcessor querystring parameter for disable cache
Hi all.
Using ImageProcessor 2.9.1 and ImageProcessor.Web 4.12.1
Is it possible to tell ImageProcessor not to cache its output with a querystring parameter like
/media/bgje545.jpg?cache=false
?I like to play aroud with an image with Rotate, Alpha, Brigtness and so on. But i do not want these requests to fill up the memory.
Hey,
Sorry this is like half an answer but hoping it's something you or somebody else can pursue in finding the full answer for.
So I have a class file called ImageProcessing.cs which attaches events to the ValidatingRequest and OnPostProcessing event handlers of ImageProcessingModule. My plan was to store a flag in the HttpContext Items in the ValidatingRequest event containing the original URL of the image (if the nocache querystring is found), and delete the file in the OnPostProcessing event using the CachedImagePath variable of PostProcessingEventArgs which is the absolute path to the newly cached image.
Unfortunately CachedImagePath is no longer part of PostProcessingEventArgs & the documentation (https://imageprocessor.org/imageprocessor-web/imageprocessingmodule/) is out of date and unable to find an alternative.
Here's what I've started, good luck to anybody who finds a solution:
Regards,
Andy
Hi Andy.
I will try to play around with the ImageProcessingModule.OnPostProcessing and post if i find a way :)
I don't know about a query string parameter, but there is a cache config file: https://imageprocessor.org/imageprocessor-web/configuration/#cacheconfig
You could set
maxDays
to a low value andtrimCache
to true, and that might help, but I'm not sure.Hi Nicholas.
Yes i could, but i want to keep the served frontend images in the memory/cache to display for the user.
So its only in the backoffice where i play around with the image filters that i want these request not to be cached.
Do you know if thats possible to set in the cache.config?
is working on a reply...