mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 01:23:53 -07:00
Added cache breaking based on hash rather than version
This commit is contained in:
parent
dbcabd6df6
commit
c4e8e3ebc7
15 changed files with 90 additions and 31 deletions
43
src/NzbDrone.Api/Frontend/Mappers/CacheBreakerProvider.cs
Normal file
43
src/NzbDrone.Api/Frontend/Mappers/CacheBreakerProvider.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Crypto;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Api.Frontend.Mappers
|
||||
{
|
||||
public interface ICacheBreakerProvider
|
||||
{
|
||||
string AddCacheBreakerToPath(string resourceUrl);
|
||||
}
|
||||
|
||||
public class CacheBreakerProvider : ICacheBreakerProvider
|
||||
{
|
||||
private readonly IEnumerable<IMapHttpRequestsToDisk> _diskMappers;
|
||||
private readonly IHashProvider _hashProvider;
|
||||
|
||||
public CacheBreakerProvider(IEnumerable<IMapHttpRequestsToDisk> diskMappers, IHashProvider hashProvider)
|
||||
{
|
||||
_diskMappers = diskMappers;
|
||||
_hashProvider = hashProvider;
|
||||
}
|
||||
|
||||
public string AddCacheBreakerToPath(string resourceUrl)
|
||||
{
|
||||
if (!ShouldBreakCache(resourceUrl))
|
||||
{
|
||||
return resourceUrl;
|
||||
}
|
||||
|
||||
var mapper = _diskMappers.Single(m => m.CanHandle(resourceUrl));
|
||||
var pathToFile = mapper.Map(resourceUrl);
|
||||
var hash = _hashProvider.ComputeMd5(pathToFile).ToBase64();
|
||||
|
||||
return resourceUrl + "?h=" + hash;
|
||||
}
|
||||
|
||||
private static bool ShouldBreakCache(string path)
|
||||
{
|
||||
return !path.EndsWith(".ics") && !path.EndsWith("main");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue