Merge pull request #10122 from cvium/remove_unnecessary_memorycache

This commit is contained in:
Bond-009 2023-08-20 20:06:21 +02:00 committed by GitHub
commit 260680d727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 18 deletions

View File

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

View File

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

View File

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

View File

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