本文整理汇总了C#中ICacheManager.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheManager.Get方法的具体用法?C# ICacheManager.Get怎么用?C# ICacheManager.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICacheManager
的用法示例。
在下文中一共展示了ICacheManager.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccessTokenManager
public AccessTokenManager(IAuthorizationCodeManager authorizationCodeManager,
ICacheManager cache
)
{
_authorizationCodeManager = authorizationCodeManager;
_cacheAccessToken = cache.Get<string, UserLite>("accessToken");
_cacheRefreshToken = cache.Get<string, UserLite>("refreshToken");
}
示例2: CounterModel
public CounterModel(ICacheManager<int> cache, long adds)
{
this.Adds = adds;
this.AboutClicks = cache.Get("about");
this.IndexClicks = cache.Get("index");
this.ContactClicks = cache.Get("contact");
this.Likes = cache.Get("like");
}
示例3: CounterModel
public CounterModel(ICacheManager<int> cache, int adds)
{
if (cache == null)
{
throw new ArgumentNullException(nameof(cache));
}
this.Adds = adds;
this.AboutClicks = cache.Get("about");
this.IndexClicks = cache.Get("index");
this.ContactClicks = cache.Get("contact");
this.Likes = cache.Get("like");
}
示例4: GetBlogEntryComments
public List<BlogEntryComment> GetBlogEntryComments()
{
if (CacheManager != null)
{
_cache = CacheManager.FirstOrDefault();
if (_cache != null && _cache.Get<List<BlogEntryComment>>(BlogCommentKey) != null)
{
return _cache.Get<List<BlogEntryComment>>(BlogCommentKey);
}
else
{
var blogEntryComments = (from comment in DataBase.Table
select
new BlogEntryComment
{
Id = comment.Id,
Name = comment.Name,
Comment = comment.Comment,
Email = comment.Email,
Homepage = comment.Homepage,
AdminPost = comment.AdminPost,
BlogEntryId = comment.BlogEntryId
}).ToList();
if (_cache != null)
_cache.Set(BlogCommentKey, blogEntryComments,
ConfigurationManager.AppSettings.Get(ConfigurationCacheKey) == null
? int.MaxValue
: int.Parse(ConfigurationManager.AppSettings.Get(ConfigurationCacheKey)));
return blogEntryComments;
}
}
else
{
return (from comment in DataBase.Table
select
new BlogEntryComment
{
Id = comment.Id,
Name = comment.Name,
Comment = comment.Comment,
Email = comment.Email,
Homepage = comment.Homepage,
AdminPost = comment.AdminPost,
BlogEntryId = comment.BlogEntryId,
Created = comment.Created,
Modified = comment.Modified
}).ToList();
}
}
示例5: GetCategoryList
/// <summary>
/// Get category list
/// </summary>
/// <param name="categoryService">Category service</param>
/// <param name="cacheManager">Cache manager</param>
/// <param name="showHidden">A value indicating whether to show hidden records</param>
/// <returns>Category list</returns>
public static List<SelectListItem> GetCategoryList(ICategoryService categoryService, ICacheManager cacheManager, bool showHidden = false)
{
string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORIES_LIST_KEY, showHidden);
var categoryListItems = cacheManager.Get(cacheKey, () =>
{
var categories = categoryService.GetAllCategories(showHidden: showHidden);
return categories.Select(c => new SelectListItem
{
Text = c.GetFormattedBreadCrumb(categories),
Value = c.Id.ToString()
});
});
var result = new List<SelectListItem>();
//clone the list to ensure that "selected" property is not set
foreach (var item in categoryListItems)
{
result.Add(new SelectListItem
{
Text = item.Text,
Value = item.Value
});
}
return result;
}
示例6: PrepareProductSpecificationModel
public static IList<ProductSpecificationModel> PrepareProductSpecificationModel(this Controller controller,
IWorkContext workContext,
ISpecificationAttributeService specificationAttributeService,
ICacheManager cacheManager,
Product product)
{
if (product == null)
throw new ArgumentNullException("product");
string cacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_SPECS_MODEL_KEY, product.Id, workContext.WorkingLanguage.Id);
return cacheManager.Get(cacheKey, () =>
{
var model = specificationAttributeService.GetProductSpecificationAttributesByProductId(product.Id, null, true)
.Select(psa =>
{
return new ProductSpecificationModel()
{
SpecificationAttributeId = psa.SpecificationAttributeOption.SpecificationAttributeId,
SpecificationAttributeName = psa.SpecificationAttributeOption.SpecificationAttribute.GetLocalized(x => x.Name),
SpecificationAttributeOption = !String.IsNullOrEmpty(psa.CustomValue) ? psa.CustomValue : psa.SpecificationAttributeOption.GetLocalized(x => x.Name),
};
}).ToList();
return model;
});
}
示例7: ClientManager
public ClientManager(IClientLoader clientLoader, ICacheManager cache, IRepository<UserClient> repUserClient)
{
_clientLoader = clientLoader;
_cacheClient = cache.Get<string, IEnumerable<Client>>("client");
_repUserClient = repUserClient;
Logger = NullLogger.Instance;
}
示例8: AccountPermissionsManager
public AccountPermissionsManager(IEnumerable<IUserPermissionPattern> userPermissionsPattern,
ICacheManager cacheManager,
IEventManager eventManager,
IAccountService accountService
)
{
_userPermissionsPattern = userPermissionsPattern;
_userPermissionsCache = cacheManager.Get<int, IEnumerable<string>>("USER_PERMISSIONS_CACHE");
_eventManager = eventManager;
_accountService = accountService;
}
示例9: AttachFloorItemHtmlDesign
public static void AttachFloorItemHtmlDesign(this Controller controller, FloorPlan plan, ICacheManager cache)
{
var floorItems = plan.FloorTables;
foreach (var item in floorItems)
{
item.TableDesign = cache.Get<string>(string.Format(CacheKeys.FLOOR_PLAN_TABLE_DESIGN,controller.User.Identity.GetDatabaseName(),item.FloorTableId), () =>
{
return controller.RenderPartialViewToString("~/Views/Floor/GetFloorItemTemplate.cshtml", item);
});
}
}
示例10: DefaultAccountService
public DefaultAccountService(ICacheManager cacheManager,
IRepository<Account> repAccount,
IEnumerable<IAccountProvider> accountProviders,
IEncryption encryption,
IRepository<AccountClient> repAccountClient)
{
_accountCache = cacheManager.Get<string, IEnumerable<Account>>("AllAccount");
_repAccount = repAccount;
_accountProviders = accountProviders;
_encryption = encryption;
_repAccountClient = repAccountClient;
Logger = NullLogger.Instance;
}
示例11: GetBlogEntryFiles
public List<BlogEntryFile> GetBlogEntryFiles()
{
if (CacheManager != null)
{
_cache = CacheManager.FirstOrDefault();
if (_cache != null && _cache.Get<List<BlogEntryFile>>(BlogFileServiceKey) != null)
{
return _cache.Get<List<BlogEntryFile>>(BlogFileServiceKey);
}
else
{
var blogEntryFiles = (from file in DataBase.Table.ToList()
select new
BlogEntryFile
{
Name = file.Name,
Extension = file.Extension
}).ToList();
if (_cache != null)
_cache.Set(BlogFileServiceKey, blogEntryFiles,
ConfigurationManager.AppSettings.Get(ConfigurationCacheKey) == null
? int.MaxValue
: int.Parse(ConfigurationManager.AppSettings.Get(ConfigurationCacheKey)));
return blogEntryFiles;
}
}
else
{
return (from file in DataBase.Table.ToList()
select new
BlogEntryFile
{
Name = file.Name,
Extension = file.Extension
}).ToList();
}
}
示例12: PrepareProductSpecificationModel
public static IList<ProductSpecificationModel> PrepareProductSpecificationModel(this Controller controller,
IWorkContext workContext,
ISpecificationAttributeService specificationAttributeService,
ICacheManager cacheManager,
Product product)
{
if (product == null)
throw new ArgumentNullException("product");
string cacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_SPECS_MODEL_KEY, product.Id, workContext.WorkingLanguage.Id);
return cacheManager.Get(cacheKey, () =>
specificationAttributeService.GetProductSpecificationAttributes(product.Id, 0, null, true)
.Select(psa =>
{
var m = new ProductSpecificationModel
{
SpecificationAttributeId = psa.SpecificationAttributeOption.SpecificationAttributeId,
SpecificationAttributeName = psa.SpecificationAttributeOption.SpecificationAttribute.GetLocalized(x => x.Name),
ColorSquaresRgb = psa.SpecificationAttributeOption.ColorSquaresRgb
};
switch (psa.AttributeType)
{
case SpecificationAttributeType.Option:
m.ValueRaw = HttpUtility.HtmlEncode(psa.SpecificationAttributeOption.GetLocalized(x => x.Name));
break;
case SpecificationAttributeType.CustomText:
m.ValueRaw = HttpUtility.HtmlEncode(psa.CustomValue);
break;
case SpecificationAttributeType.CustomHtmlText:
m.ValueRaw = psa.CustomValue;
break;
case SpecificationAttributeType.Hyperlink:
m.ValueRaw = string.Format("<a href='{0}' target='_blank'>{0}</a>", psa.CustomValue);
break;
default:
break;
}
return m;
}).ToList()
);
}
示例13: PrepareSelectList
protected IList<SelectListItem> PrepareSelectList(IUserService userService, ICacheManager cacheManager,
Guid selectedUserId, PublishingStatus status = PublishingStatus.Active)
{
string cacheKey = ModelCacheEventUser.USERS_MODEL_KEY.FormatWith(
"SelectList.{0}".FormatWith(status.ToString()));
var cacheModel = cacheManager.Get(cacheKey, () =>
{
var users = userService.GetAll(status)
.Select(user =>
{
return new SelectListItem()
{
Value = user.RowId.ToString(),
Text = user.GetFullName(),
Selected = user.RowId.Equals(selectedUserId)
};
})
.ToList();
return users;
});
return cacheModel;
}
示例14: RandomRWTest
public static void RandomRWTest(ICacheManager<Item> cache)
{
cache.Clear();
const string keyPrefix = "RWKey_";
const int actionsPerIteration = 104;
const int initialLoad = 1000;
int iterations = 0;
int removeFails = 0;
var keyIndex = 0;
var random = new Random();
Action create = () =>
{
if (keyIndex > 10000)
{
keyIndex = initialLoad;
}
Interlocked.Increment(ref keyIndex);
var key = keyPrefix + keyIndex;
var newValue = Guid.NewGuid().ToString();
var item = Item.Generate();
cache.AddOrUpdate(key, item, p =>
{
p.SomeStrings.Add(newValue);
return p;
});
};
Action read = () =>
{
for (var i = 0; i < 100; i++)
{
var val = cache.Get(keyPrefix + random.Next(1, keyIndex));
}
};
Action remove = () =>
{
const int maxTries = 10;
bool result = false;
var tries = 0;
string key;
do
{
tries++;
key = keyPrefix + random.Next(1, keyIndex);
result = cache.Remove(key);
if (!result)
{
Interlocked.Increment(ref removeFails);
}
}
while (!result && tries < maxTries);
};
Action report = () =>
{
while (true)
{
Thread.Sleep(1000);
Console.WriteLine(
"Index is at {0} Items in Cache: {1} failed removes {4} runs: {2} \t{3}",
keyIndex,
cache.CacheHandles.First().Count,
iterations,
iterations * actionsPerIteration,
removeFails);
Console.ForegroundColor = ConsoleColor.DarkGray;
foreach (var handle in cache.CacheHandles)
{
var stats = handle.Stats;
Console.WriteLine(string.Format(
"Items: {0}, Hits: {1}, Miss: {2}, Remove: {3} Adds: {4}",
stats.GetStatistic(CacheStatsCounterType.Items),
stats.GetStatistic(CacheStatsCounterType.Hits),
stats.GetStatistic(CacheStatsCounterType.Misses),
stats.GetStatistic(CacheStatsCounterType.RemoveCalls),
stats.GetStatistic(CacheStatsCounterType.AddCalls)));
}
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
iterations = 0;
removeFails = 0;
}
};
for (var i = 0; i < initialLoad; i++)
{
create();
}
Task.Factory.StartNew(report);
while (true)
//.........这里部分代码省略.........
示例15: TestEachMethod
public static void TestEachMethod(ICacheManager<object> cache)
{
cache.Clear();
cache.Add("key", "value", "region");
cache.AddOrUpdate("key", "region", "value", _ => "update value", 22);
cache.Expire("key", "region", TimeSpan.FromDays(1));
var val = cache.Get("key", "region");
var item = cache.GetCacheItem("key", "region");
cache.Put("key", "put value");
cache.RemoveExpiration("key");
object update2;
cache.TryUpdate("key", "region", _ => "update 2 value", out update2);
object update3 = cache.Update("key", "region", _ => "update 3 value");
cache.Remove("key", "region");
cache.Clear();
cache.ClearRegion("region");
}