mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
non-working cached repository.
This commit is contained in:
parent
23e9c725f3
commit
5b2410da3f
6 changed files with 92 additions and 5 deletions
|
@ -32,6 +32,7 @@ namespace NzbDrone.Core.Datastore
|
|||
TModel Single();
|
||||
}
|
||||
|
||||
|
||||
public class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : ModelBase, new()
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
|
@ -202,6 +203,16 @@ namespace NzbDrone.Core.Datastore
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void OnModelChanged(IEnumerable<TModel> models)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void OnModelDeleted(IEnumerable<TModel> models)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual bool PublishModelEvents
|
||||
{
|
||||
get { return false; }
|
||||
|
|
40
NzbDrone.Core/Datastore/CachedBasicRepository.cs
Normal file
40
NzbDrone.Core/Datastore/CachedBasicRepository.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public abstract class CachedBasicRepository<TModel> : BasicRepository<TModel> where TModel : ModelBase, new()
|
||||
{
|
||||
private readonly ICacheManger _cacheManger;
|
||||
|
||||
protected CachedBasicRepository(IDatabase database, IMessageAggregator messageAggregator)
|
||||
: base(database, messageAggregator)
|
||||
{
|
||||
_cacheManger = new CacheManger();
|
||||
}
|
||||
|
||||
protected ICached<T> GetCache<T>(string name)
|
||||
{
|
||||
return _cacheManger.GetCache<T>(GetType(), name);
|
||||
}
|
||||
|
||||
protected override void OnModelChanged(IEnumerable<TModel> models)
|
||||
{
|
||||
PurgeCache();
|
||||
}
|
||||
|
||||
protected override void OnModelDeleted(IEnumerable<TModel> models)
|
||||
{
|
||||
PurgeCache();
|
||||
}
|
||||
|
||||
private void PurgeCache()
|
||||
{
|
||||
foreach (var model in _cacheManger.Caches)
|
||||
{
|
||||
model.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue