mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-22 16:54:46 +03:00
reduce use of timers throughout the system
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using MoreLinq;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Networking
|
||||
@@ -14,14 +13,11 @@ namespace MediaBrowser.Common.Implementations.Networking
|
||||
public abstract class BaseNetworkManager
|
||||
{
|
||||
protected ILogger Logger { get; private set; }
|
||||
private Timer _clearCacheTimer;
|
||||
private DateTime _lastRefresh;
|
||||
|
||||
protected BaseNetworkManager(ILogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
|
||||
// Can't use network change events due to a crash in Linux
|
||||
_clearCacheTimer = new Timer(ClearCacheTimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||
}
|
||||
|
||||
private void ClearCacheTimerCallback(object state)
|
||||
@@ -41,15 +37,20 @@ namespace MediaBrowser.Common.Implementations.Networking
|
||||
/// <returns>IPAddress.</returns>
|
||||
public IEnumerable<IPAddress> GetLocalIpAddresses()
|
||||
{
|
||||
if (_localIpAddresses == null)
|
||||
var forceRefresh = (DateTime.UtcNow - _lastRefresh).TotalMinutes >= 1;
|
||||
|
||||
if (_localIpAddresses == null || forceRefresh)
|
||||
{
|
||||
lock (_localIpAddressSyncLock)
|
||||
{
|
||||
if (_localIpAddresses == null)
|
||||
forceRefresh = (DateTime.UtcNow - _lastRefresh).TotalMinutes >= 1;
|
||||
|
||||
if (_localIpAddresses == null || forceRefresh)
|
||||
{
|
||||
var addresses = GetLocalIpAddressesInternal().ToList();
|
||||
|
||||
_localIpAddresses = addresses;
|
||||
_lastRefresh = DateTime.UtcNow;
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user