本文整理汇总了C#中Cache.GetOrCreate方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.GetOrCreate方法的具体用法?C# Cache.GetOrCreate怎么用?C# Cache.GetOrCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.GetOrCreate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Listing
public Listing(
CarsContext context,
Cache cache,
SourceSite source,
string sourceId,
string make,
string model,
int year,
int price,
int mileage,
string location,
string description)
{
Active = true;
DateAdded = DateTime.Now;
DateLastSeen = DateTime.Now;
Source = source;
SourceId = sourceId;
Year = year;
Price = price;
Mileage = mileage;
Description = description;
MakeId = cache.GetOrCreate<Make>(make, () => context.Set<Make>().GetOrCreate(make));
ModelId = cache.GetOrCreate<Model>(model, () => context.Set<Model>().GetOrCreate(model));
County = EnumHelpers.FromString<County>(location);
}
示例2: GetOrCreateMake_CallWhenNotInCache
public void GetOrCreateMake_CallWhenNotInCache()
{
var cache = new Cache();
var mockGetOrCreate = MockRepository.GenerateMock<Func<int>>();
cache.GetOrCreate<Make>("_", mockGetOrCreate);
mockGetOrCreate.AssertWasCalled(a => a.Invoke());
}
示例3: UpdateCore
private static void UpdateCore(Cache cache)
{
cache.GetOrCreate<object>(UpdatedStatsCacheKey, () => {
using (var db = Database.Open("Stats")) {
DateTime? lastLog = db.QueryValue("Select top 1 LogTime from Stats order by LogTime desc");
if (!lastLog.HasValue || DateTime.UtcNow.Subtract(lastLog.Value).TotalMinutes > 30) {
Statistics stats = PackageRepository.GetCurrentStatistics(cache);
db.Execute("Insert into Stats (LogTime, Downloads, UniquePackages, TotalPackages) values (GETUTCDATE(), @0, @1, @2)",
stats.TotalDownloads,
stats.UniqueCount,
stats.TotalCount);
}
}
return new object();
}, TimeSpan.FromMinutes(5));
}
示例4: GetCurrentStatistics
public static Statistics GetCurrentStatistics(Cache cache)
{
return cache.GetOrCreate<Statistics>("repositoryStats", GetStatisticsInternal, CacheTime);
}
示例5: GetMetaStatistics
public static MetaStatistics GetMetaStatistics(Cache cache)
{
return cache.GetOrCreate<MetaStatistics>("metastats", () => GetMetaStatisticsCore(cache), PackageRepository.CacheTime);
}