This commit is contained in:
Jamie Rees 2019-04-23 13:40:17 +01:00
commit 975a162edd
84 changed files with 812 additions and 282 deletions

View file

@ -28,18 +28,15 @@ namespace Ombi.Helpers
return result;
}
//using (await _mutex.LockAsync())
if (_memoryCache.TryGetValue(cacheKey, out result))
{
if (_memoryCache.TryGetValue(cacheKey, out result))
{
return result;
}
result = await factory();
_memoryCache.Set(cacheKey, result, absoluteExpiration);
return result;
}
result = await factory();
_memoryCache.Set(cacheKey, result, absoluteExpiration);
return result;
}
public void Remove(string key)
@ -47,34 +44,34 @@ namespace Ombi.Helpers
_memoryCache.Remove(key);
}
public T GetOrAdd<T>(string cacheKey, Func<T> factory, DateTime absoluteExpiration)
public T GetOrAdd<T>(string cacheKey, Func<T> factory, DateTime absoluteExpiration)
{
// locks get and set internally
if (_memoryCache.TryGetValue<T>(cacheKey, out var result))
{
// locks get and set internally
if (_memoryCache.TryGetValue<T>(cacheKey, out var result))
return result;
}
lock (TypeLock<T>.Lock)
{
if (_memoryCache.TryGetValue(cacheKey, out result))
{
return result;
}
lock (TypeLock<T>.Lock)
{
if (_memoryCache.TryGetValue(cacheKey, out result))
{
return result;
}
result = factory();
_memoryCache.Set(cacheKey, result, absoluteExpiration);
result = factory();
_memoryCache.Set(cacheKey, result, absoluteExpiration);
return result;
}
return result;
}
}
private static class TypeLock<T>
{
public static object Lock { get; } = new object();
}
private static class TypeLock<T>
{
public static object Lock { get; } = new object();
}
}
}

View file

@ -16,7 +16,6 @@
// You should have received a copy of the GNU Lesser General Public
// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.
using System;
/// <summary>
/// Helper class that provides common values for the cron expressions.
/// </summary>
@ -44,7 +43,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Hourly(int minute)
{
return $"{minute} * * * *";
return $"0 {minute} 0/1 1/1 * ? *";
}
/// <summary>
@ -73,7 +72,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Daily(int hour, int minute)
{
return $"{minute} {hour} * * *";
return $"0 {minute} {hour} 1/1 * ? *";
}
/// <summary>
@ -114,7 +113,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute)
{
return $"{minute} {hour} * * {(int)dayOfWeek}";
return $"0 {minute} {hour} ? * {(int)dayOfWeek} *";
}
/// <summary>
@ -219,7 +218,7 @@
/// <param name="interval">The number of minutes to wait between every activation.</param>
public static string MinuteInterval(int interval)
{
return $"*/{interval} * * * *";
return $"0 0/{interval} * 1/1 * ? *";
}
/// <summary>
@ -228,7 +227,7 @@
/// <param name="interval">The number of hours to wait between every activation.</param>
public static string HourInterval(int interval)
{
return $"0 */{interval} * * *";
return $"0 0 0/{interval} 1/1 * ? *";
}
/// <summary>
@ -237,7 +236,7 @@
/// <param name="interval">The number of days to wait between every activation.</param>
public static string DayInterval(int interval)
{
return $"0 0 */{interval} * *";
return $"0 0 12 1/{interval} * ? *";
}
/// <summary>
@ -249,4 +248,39 @@
return $"0 0 1 */{interval} *";
}
}
//
// Summary:
// Specifies the day of the week.
public enum DayOfWeek
{
//
// Summary:
// Indicates Sunday.
Sunday = 1,
//
// Summary:
// Indicates Monday.
Monday = 2,
//
// Summary:
// Indicates Tuesday.
Tuesday = 3,
//
// Summary:
// Indicates Wednesday.
Wednesday = 4,
//
// Summary:
// Indicates Thursday.
Thursday = 5,
//
// Summary:
// Indicates Friday.
Friday = 6,
//
// Summary:
// Indicates Saturday.
Saturday = 7
}
}