|
|
|
@ -3,12 +3,12 @@ using Recyclarr.Config.Models;
|
|
|
|
|
|
|
|
|
|
namespace Recyclarr.Cli.Cache;
|
|
|
|
|
|
|
|
|
|
public class CachePersister(ILogger log, IServiceCache cache) : ICachePersister
|
|
|
|
|
public class CachePersister(ILogger log, IServiceCache serviceCache) : ICachePersister
|
|
|
|
|
{
|
|
|
|
|
public CustomFormatCache Load(IServiceConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
var cache1 = cache.Load<CustomFormatCache>(config);
|
|
|
|
|
if (cache1 == null)
|
|
|
|
|
var cache = serviceCache.Load<CustomFormatCache>(config);
|
|
|
|
|
if (cache == null)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Custom format cache does not exist; proceeding without it");
|
|
|
|
|
return new CustomFormatCache();
|
|
|
|
@ -16,20 +16,20 @@ public class CachePersister(ILogger log, IServiceCache cache) : ICachePersister
|
|
|
|
|
|
|
|
|
|
// If the version is higher OR lower, we invalidate the cache. It means there's an
|
|
|
|
|
// incompatibility that we do not support.
|
|
|
|
|
if (cache1.Version != CustomFormatCache.LatestVersion)
|
|
|
|
|
if (cache.Version != CustomFormatCache.LatestVersion)
|
|
|
|
|
{
|
|
|
|
|
log.Information("Cache version mismatch ({OldVersion} vs {LatestVersion}); ignoring cache data",
|
|
|
|
|
cache1.Version, CustomFormatCache.LatestVersion);
|
|
|
|
|
cache.Version, CustomFormatCache.LatestVersion);
|
|
|
|
|
throw new CacheException("Version mismatch");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cache1;
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(IServiceConfiguration config, CustomFormatCache cache1)
|
|
|
|
|
public void Save(IServiceConfiguration config, CustomFormatCache cache)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Saving Cache with {Mappings}", JsonSerializer.Serialize(cache1.TrashIdMappings));
|
|
|
|
|
log.Debug("Saving Cache with {Mappings}", JsonSerializer.Serialize(cache.TrashIdMappings));
|
|
|
|
|
|
|
|
|
|
cache.Save(cache1, config);
|
|
|
|
|
serviceCache.Save(cache, config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|