本文整理汇总了C#中Cache.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Fill方法的具体用法?C# Cache.Fill怎么用?C# Cache.Fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.Fill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RepositoryData
public RepositoryData(IRepositoryConfig repositoryConfig)
{
if (repositoryConfig == null) throw new ArgumentNullException("repositoryConfig");
this.repositoryConfig = repositoryConfig;
if (!string.IsNullOrWhiteSpace(repositoryConfig.PersistedDataPath))
{
this.IndexesCached = new Lazy<Cache<Type, IIndex>>(() =>
{
var path = Path.Combine(this.repositoryConfig.PersistedDataPath, "Indexes");
if (!Directory.Exists(path)) return new Cache<Type, IIndex>(this.repositoryConfig.Indexes.ToDictionary(index => index.GetType(), index => index));
var cache = new Cache<Type, IIndex>();
Directory.EnumerateFiles(path)
.Each(fileName =>
{
using (var entityFileStream = File.OpenRead(fileName))
{
var indexContainer = JsonSerializer.DeserializeFromStream<IndexContainer>(entityFileStream);
cache.Fill(indexContainer.Type, indexContainer.Index);
}
});
return cache;
});
this.EntitiesCached = new Lazy<Cache<Type, List<dynamic>>>(() =>
{
var path = Path.Combine(this.repositoryConfig.PersistedDataPath, "Entities");
if (!Directory.Exists(path)) return new Cache<Type, List<dynamic>>();
var cache = new Cache<Type, List<dynamic>>();
Directory.EnumerateFiles(path)
.Each(fileName =>
{
using (var entityFileStream = File.OpenRead(fileName))
{
var entityContainer = JsonSerializer.DeserializeFromStream<EntityContainer>(entityFileStream);
cache.Fill(entityContainer.Type, entityContainer.Entities);
}
});
return cache;
});
}
else
{
this.IndexesCached = new Lazy<Cache<Type, IIndex>>(() => new Cache<Type, IIndex>(repositoryConfig.Indexes.ToDictionary(index => index.GetType(), index => index)));
this.EntitiesCached = new Lazy<Cache<Type, List<dynamic>>>(() => new Cache<Type, List<dynamic>>());
}
}