I have a page where I list all files that exists in a specific media folder. The files are not added manually to the document node, but listed programmatically with a surface controller, like this:
var children = Umbraco.TypedMedia(model.Node).Children; model.Files = children.Where(c => c.DocumentTypeAlias.Equals("File")).OrderBy(c => c.Name);
When a file is added it's all fine and dandy, it shows up in the list as expected. But when a file is deleted it still shows up in the list.
I know I can delete the umbraco.config file to clear the cache, but it's not really an acceptable solution since editors will add and remove files all the time. Is there a way to clear the (media) cache programmatically or manually via the umbraco interface?
The media cache should be up to date even when items have been deleted. I guess if you wanted to make sure, you could hook into the delete media event and refresh the cache from there. I'm fairly certain the core events do this anyway.
using System;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web.Cache;
namespace Application
{
public class MediaCacheRefresherEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
MediaService.Deleted
+= (sender, args) => DistributedCache.Instance.RefreshAll(new Guid(DistributedCache.MediaCacheRefresherId));
}
}
}
Thanks for your input. To do this change I would need to rebuild the core lib, which seems a bit overkill and seems like it could hurt the posibility to upgrade later on. Right?
I tried adding this line into the controller that fetches the files, but it didn't make any difference.
I have this problem myself with 7.6.3. We delete a media file but cannot get it to stop being listed no matter what we do. The actual file on disk remains behind as well.
Clearing media cache for deleted files
I have a page where I list all files that exists in a specific media folder. The files are not added manually to the document node, but listed programmatically with a surface controller, like this:
When a file is added it's all fine and dandy, it shows up in the list as expected. But when a file is deleted it still shows up in the list.
I know I can delete the umbraco.config file to clear the cache, but it's not really an acceptable solution since editors will add and remove files all the time. Is there a way to clear the (media) cache programmatically or manually via the umbraco interface?
Thanks,
Daniel
Hi Daniel,
The media cache should be up to date even when items have been deleted. I guess if you wanted to make sure, you could hook into the delete media event and refresh the cache from there. I'm fairly certain the core events do this anyway.
Thanks, Dan.
Hi Dan,
Thanks for your input. To do this change I would need to rebuild the core lib, which seems a bit overkill and seems like it could hurt the posibility to upgrade later on. Right?
I tried adding this line into the controller that fetches the files, but it didn't make any difference.
Thanks,
Daniel
I have this problem myself with 7.6.3. We delete a media file but cannot get it to stop being listed no matter what we do. The actual file on disk remains behind as well.
is working on a reply...