You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
897 B
38 lines
897 B
using System;
|
|
using System.Collections.Generic;
|
|
using NzbDrone.Common.Cache;
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
namespace NzbDrone.Common.Instrumentation.Sentry
|
|
{
|
|
public class SentryDebounce
|
|
{
|
|
private readonly TimeSpan _ttl;
|
|
private readonly Cached<bool> _cache;
|
|
|
|
public SentryDebounce()
|
|
{
|
|
_cache = new Cached<bool>();
|
|
_ttl = RuntimeInfo.IsProduction ? TimeSpan.FromHours(1) : TimeSpan.FromSeconds(10);
|
|
}
|
|
|
|
public bool Allowed(IEnumerable<string> fingerPrint)
|
|
{
|
|
var key = string.Join("|", fingerPrint);
|
|
var exists = _cache.Find(key);
|
|
|
|
if (exists)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_cache.Set(key, true, _ttl);
|
|
return true;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_cache.Clear();
|
|
}
|
|
}
|
|
} |