refactor: use ConcurrentDictionary when IMemoryCache isn't needed

pull/10122/head
cvium 10 months ago
parent 3e9bead697
commit 2e32e335ac

@ -3,6 +3,7 @@
#pragma warning disable CS1591
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@ -63,7 +64,7 @@ namespace Emby.Server.Implementations.Library
private const string ShortcutFileExtension = ".mblink";
private readonly ILogger<LibraryManager> _logger;
private readonly IMemoryCache _memoryCache;
private readonly ConcurrentDictionary<Guid, BaseItem> _cache;
private readonly ITaskManager _taskManager;
private readonly IUserManager _userManager;
private readonly IUserDataManager _userDataRepository;
@ -111,7 +112,6 @@ namespace Emby.Server.Implementations.Library
/// <param name="mediaEncoder">The media encoder.</param>
/// <param name="itemRepository">The item repository.</param>
/// <param name="imageProcessor">The image processor.</param>
/// <param name="memoryCache">The memory cache.</param>
/// <param name="namingOptions">The naming options.</param>
/// <param name="directoryService">The directory service.</param>
public LibraryManager(
@ -128,7 +128,6 @@ namespace Emby.Server.Implementations.Library
IMediaEncoder mediaEncoder,
IItemRepository itemRepository,
IImageProcessor imageProcessor,
IMemoryCache memoryCache,
NamingOptions namingOptions,
IDirectoryService directoryService)
{
@ -145,7 +144,7 @@ namespace Emby.Server.Implementations.Library
_mediaEncoder = mediaEncoder;
_itemRepository = itemRepository;
_imageProcessor = imageProcessor;
_memoryCache = memoryCache;
_cache = new ConcurrentDictionary<Guid, BaseItem>();
_namingOptions = namingOptions;
_extraResolver = new ExtraResolver(loggerFactory.CreateLogger<ExtraResolver>(), namingOptions, directoryService);
@ -300,7 +299,7 @@ namespace Emby.Server.Implementations.Library
}
}
_memoryCache.Set(item.Id, item);
_cache[item.Id] = item;
}
public void DeleteItem(BaseItem item, DeleteOptions options)
@ -441,7 +440,7 @@ namespace Emby.Server.Implementations.Library
_itemRepository.DeleteItem(child.Id);
}
_memoryCache.Remove(item.Id);
_cache.TryRemove(item.Id, out _);
ReportItemRemoved(item, parent);
}
@ -1233,7 +1232,7 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentException("Guid can't be empty", nameof(id));
}
if (_memoryCache.TryGetValue(id, out BaseItem item))
if (_cache.TryGetValue(id, out BaseItem item))
{
return item;
}

@ -3,6 +3,7 @@
#pragma warning disable CS1591
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -23,14 +24,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
public abstract class BaseTunerHost
{
private readonly IMemoryCache _memoryCache;
private readonly ConcurrentDictionary<string, List<ChannelInfo>> _cache;
protected BaseTunerHost(IServerConfigurationManager config, ILogger<BaseTunerHost> logger, IFileSystem fileSystem, IMemoryCache memoryCache)
protected BaseTunerHost(IServerConfigurationManager config, ILogger<BaseTunerHost> logger, IFileSystem fileSystem)
{
Config = config;
Logger = logger;
_memoryCache = memoryCache;
FileSystem = fileSystem;
_cache = new ConcurrentDictionary<string, List<ChannelInfo>>();
}
protected IServerConfigurationManager Config { get; }
@ -51,7 +52,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
var key = tuner.Id;
if (enableCache && !string.IsNullOrEmpty(key) && _memoryCache.TryGetValue(key, out List<ChannelInfo> cache))
if (enableCache && !string.IsNullOrEmpty(key) && _cache.TryGetValue(key, out List<ChannelInfo> cache))
{
return cache;
}
@ -61,7 +62,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
if (!string.IsNullOrEmpty(key) && list.Count > 0)
{
_memoryCache.Set(key, list);
_cache[key] = list;
}
return list;

@ -50,9 +50,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
IHttpClientFactory httpClientFactory,
IServerApplicationHost appHost,
ISocketFactory socketFactory,
IStreamHelper streamHelper,
IMemoryCache memoryCache)
: base(config, logger, fileSystem, memoryCache)
IStreamHelper streamHelper)
: base(config, logger, fileSystem)
{
_httpClientFactory = httpClientFactory;
_appHost = appHost;

@ -54,9 +54,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
IHttpClientFactory httpClientFactory,
IServerApplicationHost appHost,
INetworkManager networkManager,
IStreamHelper streamHelper,
IMemoryCache memoryCache)
: base(config, logger, fileSystem, memoryCache)
IStreamHelper streamHelper)
: base(config, logger, fileSystem)
{
_httpClientFactory = httpClientFactory;
_appHost = appHost;

Loading…
Cancel
Save