entlib 5.0学习笔记 caching application block 3 详细配置及api使用
2011-01-27 16:54
645 查看
entlib 5.0学习笔记 caching application block 3 详细配置及api使用
1. 详细配置及使用示例
2. api使用方法
3. 参考资料及代码下载
public void ExampleScenario(ICacheManager productsCache)
{
string id = "ProductOneId";
string name = "ProductOneName";
int price = 50;
Product newProduct = new Product(id, name, price);
productsCache.Add(newProduct.ProductID, newProduct, CacheItemPriority.Normal,
null, new SlidingTime(TimeSpan.FromMinutes(5)));
}
2.2 Remove Item from Cache
public void Remove(ICacheManager cache, string key)
{
cache.Remove(key);
}
2.3 Retrieving Items from the Cache
// Read the item from the cache. If the item is not found
// in the cache, the return value will be null.
public Product GetProduct(ICacheManager cache, string key)
{
return (Product)cache.GetData(key);
}
2.4 Flushing the Cache
.Flushing removes all items in the cache
public void FlushCache(ICacheManager cache)
{
cache.Flush();
}
2.5 Loading the Cache.
public List<Product> GetProductList()
{
// This returns a list of product objects.
}
public void LoadAllProducts(ICacheManager cache)
{
List<Product>list = GetProductList();
for (int i = 0; i < list.Count; i++)
{
Product newProduct = list[i];
cache.Add(newProduct.ProductID, newProduct);
}
}
1. 详细配置及使用示例
2. api使用方法
3. 参考资料及代码下载
1. 详细配置
2. api使用方法
2.1 Add Item to Cachepublic void ExampleScenario(ICacheManager productsCache)
{
string id = "ProductOneId";
string name = "ProductOneName";
int price = 50;
Product newProduct = new Product(id, name, price);
productsCache.Add(newProduct.ProductID, newProduct, CacheItemPriority.Normal,
null, new SlidingTime(TimeSpan.FromMinutes(5)));
}
2.2 Remove Item from Cache
public void Remove(ICacheManager cache, string key)
{
cache.Remove(key);
}
2.3 Retrieving Items from the Cache
// Read the item from the cache. If the item is not found
// in the cache, the return value will be null.
public Product GetProduct(ICacheManager cache, string key)
{
return (Product)cache.GetData(key);
}
2.4 Flushing the Cache
.Flushing removes all items in the cache
public void FlushCache(ICacheManager cache)
{
cache.Flush();
}
2.5 Loading the Cache.
public List<Product> GetProductList()
{
// This returns a list of product objects.
}
public void LoadAllProducts(ICacheManager cache)
{
List<Product>list = GetProductList();
for (int i = 0; i < list.Count; i++)
{
Product newProduct = list[i];
cache.Add(newProduct.ProductID, newProduct);
}
}
相关文章推荐
- entlib 5.0学习笔记 caching application block 3 详细配置及api使用
- Unity Application Block 学习笔记之一使用配置文件
- EntLib 3.1学习笔记(1) : Caching Application Block
- EntLib 3.1学习笔记(1) : Caching Application Block
- extlib 5.0 学习笔记 cache application block 4 设计与实现
- EntLib 3.1学习笔记(4) : Logging Application Block
- entlib5.0 学习笔记 caching application block2 简单使用示例
- entlib5.0 学习笔记 caching application block2 简单使用示例
- entlib 5.0学习笔记 data access block
- EntLib 3.1学习笔记(5) : Exception Handling Application Block
- EntLib 3.1学习笔记(6) : Security Application Block
- EntLib 3.1学习笔记(6) : Security Application Block
- EntLib 3.1学习笔记(2) : Data Access Application Block
- [EntLib]微软企业库5.0 学习之路——第八步、使用Configuration Setting模块等多种方式分类管理企业库配置信息
- Unity Application Block 学习笔记之一使用接口
- Unity Application Block 学习笔记 之 在VS2012中 配置文件 自动感应
- EntLib 3.1学习笔记(3) : Cryptography Application Block
- EntLib 3.1学习笔记(2) : Data Access Application Block
- entlib 5.0学习笔记 通过配置方式实现注入
- EntLib 3.1学习笔记(4) : Logging Application Block