/// <summary> /// Resources cache /// </summary> /// <param name="source"></param> /// <param name="options"></param> public AssetCachePartResources(IAsset source, AssetCacheOptions options) { this.Source = source ?? throw new ArgumentNullException(nameof(source)); this.Options = options ?? throw new ArgumentNullException(nameof(options)); this.comparer = LineComparer.Default; this.cache = new Cache(comparer); }
/// <summary> /// Get options for cache streams /// </summary> /// <param name="options"></param> /// <returns></returns> public static bool GetCacheStreams(this AssetCacheOptions options) { object value; if (options.TryGetValue(Key_CacheStreams, out value) && value is bool _value) { return(_value); } return(true); }
/// <summary> /// Get maximum resource total size option /// </summary> /// <param name="options"></param> /// <returns></returns> public static int GetMaxResourceTotalSize(this AssetCacheOptions options) { object value; if (options.TryGetValue(Key_MaxResourceTotalSize, out value) && value is int _value) { return(_value); } return(1024 * 1024); }
/// <summary> /// Get maximum resource option /// </summary> /// <param name="options"></param> /// <returns></returns> public static int GetMaxResourceCount(this AssetCacheOptions options) { object value; if (options.TryGetValue(Key_MaxResourceCount, out value) && value is int _value) { return(_value); } return(Int32.MaxValue); }
/// <summary> /// Create new asset cache. /// </summary> /// <param name="source">The source asset whose reuqests are cached.</param> /// <param name="cacheParts">parts that handle interface specific properties, such as <see cref="AssetCachePartResources"/>, AssetStringsCachePart and AssetCulturesCachePart</param> public AssetCache(IAsset source, IEnumerable <IAssetCachePart> cacheParts) : base(cacheParts) { Options = new AssetCacheOptions(); Source = source ?? throw new ArgumentNullException(nameof(source)); this.disposeSource = true; }
/// <summary> /// Create new asset cache. /// </summary> /// <param name="source">The source asset whose reuqests are cached.</param> /// <param name="cacheParts">parts that handle interface specific properties, such as <see cref="AssetCachePartResources"/>, AssetStringsCachePart and AssetCulturesCachePart</param> /// <param name="disposeSource">Disposes <paramref name="source"/> along with cache</param> public AssetCache(IAsset source, bool disposeSource = true, params IAssetCachePart[] cacheParts) : base(cacheParts) { Options = new AssetCacheOptions(); Source = source ?? throw new ArgumentNullException(nameof(source)); this.disposeSource = disposeSource; }
/// <summary> /// Create new asset cache. /// </summary> /// <param name="source">The source asset whose requests are cached.</param> /// <param name="disposeSource">Disposes <paramref name="source"/> along with cache</param> public AssetCache(IAsset source, bool disposeSource = true) { Options = new AssetCacheOptions(); Source = source ?? throw new ArgumentNullException(nameof(source)); this.disposeSource = disposeSource; }
/// <summary> /// Create part that caches cultures. /// </summary> /// <param name="source"></param> /// <param name="options"></param> public AssetCachePartCultures(IAsset source, AssetCacheOptions options) { this.Source = source ?? throw new ArgumentNullException(nameof(source)); this.Options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> /// Set option for cache streams /// </summary> /// <param name="options"></param> /// <param name="newValue"></param> /// <returns></returns> public static AssetCacheOptions SetCacheStreams(this AssetCacheOptions options, bool newValue) { options.Set <bool>(Key_CacheStreams, newValue); return(options); }
/// <summary> /// Set maximum resource total size /// </summary> /// <param name="options"></param> /// <param name="newValue"></param> /// <returns></returns> public static AssetCacheOptions SetMaxResourceTotalSize(this AssetCacheOptions options, int newValue) { options.Set <int>(Key_MaxResourceTotalSize, newValue); return(options); }
/// <summary> /// Set whether cache should create clones of keys, or whether to use the keys that come from requests in its cache structures. /// </summary> /// <param name="options"></param> /// <param name="cloneKeys"></param> /// <returns></returns> public static AssetCacheOptions SetCloneKeys(this AssetCacheOptions options, bool cloneKeys) { options.Set <bool>(Key_CloneKeys, cloneKeys); return(options); }