public IColumnReader GetOrBuild(string key, CachingOption option, Func <IColumnReader> build) { if (option == CachingOption.Always || (ColumnCache.IsEnabled && option == CachingOption.AsConfigured)) { return(_cache.GetOrBuild(key, null, () => { IColumnReader inner = build(); if (inner == null) { return null; } if (inner is CachedColumnReader) { return inner; } return new CachedColumnReader(inner); })); } else { IColumnReader result; if (_cache.TryGet(key, out result)) { return(result); } return(build()); } }
public RockOptions(OptimizationSetting level = OptimizationSetting.Release, CodeFileOption codeFile = CodeFileOption.None, SerializationOption serialization = SerializationOption.NotSupported, CachingOption caching = CachingOption.UseCache, AllowWarning allowWarning = AllowWarning.No, string?codeFileDirectory = null) => (this.Optimization, this.CodeFile, this.Serialization, this.Caching, this.AllowWarning, this.CodeFileDirectory) =
public async Task SetCache(HttpContext context, CachedResponse response, CachingOption options) { string key = options.Key.Get(context.Request); options.Store.Set(key, response, response.Expiry); await Task.CompletedTask; }
public static void InitializeCacheEngine(CachingOption option) { var selectedCache = (option == CachingOption.CacheOnHTTPContext) ? RequestCachingEngineInstance : ApplicationCachingEngineInstance; HttpContext.Current.Session["CurrentCacheEngine"] = selectedCache; }
public static void AddCarterCaching(this IServiceCollection services, Action <CachingOption> options = null) { var cachingOptions = new CachingOption(); options(cachingOptions); services.AddCarterCaching(cachingOptions); }
public void Default_caching_option() { //Arrange & Act var cachingOption = new CachingOption(); //Assert Assert.IsType <DefaultMemoryStore>(cachingOption.Store); Assert.IsType <DefaultKeyGenerator>(cachingOption.Key); }
public CachingService( IRepository <T> repository, IEasyCachingProvider provider, IOptions <CachingOption> options) { _repository = repository; _provider = provider; _cachingOption = options.Value; }
public void Default_caching_option_with_constructor_store() { //Arrange var store = new DefaultMemoryStore(); //Act var cachingOption = new CachingOption(store); //Assert Assert.StrictEqual(store, cachingOption.Store); }
public void Default_caching_option_with_constructor_key() { //Arrange var key = new DefaultKeyGenerator(); //Act var cachingOption = new CachingOption(key); //Assert Assert.StrictEqual(key, cachingOption.Key); }
private static void AssertOptions(RockOptions options, OptimizationSetting level, CodeFileOption codeFile, SerializationOption serialization, CachingOption caching, AllowWarning allowWarnings, string codeFileDirectory) { Assert.That(options.Optimization, Is.EqualTo(level), nameof(options.Optimization)); Assert.That(options.CodeFile, Is.EqualTo(codeFile), nameof(options.CodeFile)); Assert.That(options.Serialization, Is.EqualTo(serialization), nameof(options.Serialization)); Assert.That(options.Caching, Is.EqualTo(caching), nameof(options.Caching)); Assert.That(options.AllowWarning, Is.EqualTo(allowWarnings), nameof(options.AllowWarning)); Assert.That(options.CodeFileDirectory, Is.EqualTo(codeFileDirectory), nameof(options.CodeFileDirectory)); }
public void Default_caching_option_with_constructor_store_max_size() { //Arrange const long Size = 10; //Act var cachingOption = new CachingOption(Size); var store = (DefaultMemoryStore)cachingOption.Store; //Assert Assert.StrictEqual(Size, store.SizeLimit); }
public void Service_collection_with_parameter() { //Arrange var service = A.Fake <IServiceCollection>(); var options = new CachingOption(2048); //Act service.AddCarterCaching(options); //Assert Assert.NotNull(service.Where(x => x.ServiceType == typeof(CachingOption))); }
public void Default_caching_option_with_constructor_key_and_store() { //Arrange var key = new DefaultKeyGenerator(); var store = new DefaultMemoryStore(); //Act var cachingOption = new CachingOption(key, store); //Assert Assert.StrictEqual(key, cachingOption.Key); Assert.StrictEqual(store, cachingOption.Store); }
public async Task <bool> CheckCache(HttpContext ctx, CachingOption options) { string key = options.Key.Get(ctx.Request); if (string.IsNullOrWhiteSpace(key)) { return(false); } if (options.Store.TryGetValue(key, out CachedResponse cachedResponse)) { await cachedResponse.MapToContext(ctx); return(true); } return(false); }
private void GetReader(CachingOption option = CachingOption.AsConfigured) { // If we already have a reader with appropriate caching, keep using it if (_columnReader != null && (option != CachingOption.Always || _isCached == true)) { return; } // If we had a reader but need a cached one, Dispose the previous one if (_columnReader != null) { _columnReader.Dispose(); } // Build the new reader and store a typed EnumReader copy. _columnReader = TypeProviderFactory.TryGetColumnReader(_streamProvider, ColumnDetails.Type, Path.Combine(_table.TablePath, ColumnDetails.Name), option); _enumReader = _columnReader as EnumReader; _isCached = (option == CachingOption.Always || (option == CachingOption.AsConfigured && ColumnCache.IsEnabled)); }
public CarterCachingMiddleware(RequestDelegate next, ICarterCachingService service, CachingOption options) => (this.next, this.service, this.options) = (next, service, options);
public IColumnReader BinaryReader(IStreamProvider streamProvider, string columnPath, CachingOption option) { // Cache direct byte[] columns return(ColumnCache.Instance.GetOrBuild(columnPath, option, () => { string filePath = ValuesFilePath(columnPath); if (!streamProvider.Attributes(filePath).Exists) { return null; } return new ByteReader(streamProvider.OpenRead(filePath)); })); }
public VariableIntegerReader(IStreamProvider streamProvider, string columnPathPrefix, CachingOption option) { // Look for each potential size in descending order and build the right reader and converter Type type = typeof(int); string path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(int)); if (streamProvider.Attributes(path).Exists) { _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(int), path, option, typeof(VariableIntegerReader)); _converter = null; return; } path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(ushort)); if (streamProvider.Attributes(path).Exists) { _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(ushort), path, option, typeof(VariableIntegerReader)); _converter = TypeConverterFactory.GetConverter(typeof(ushort), typeof(int)); return; } path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(byte)); _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), path, option, typeof(VariableIntegerReader)); _converter = TypeConverterFactory.GetConverter(typeof(byte), typeof(int)); }
public IColumnReader BinaryReader(IStreamProvider streamProvider, string columnPath, CachingOption option) { // Cache the byte[] and int[], not the String8[] (much lower overhead; fast to construct String8 pages) return(new String8ColumnReader(streamProvider, columnPath, option)); }
public String8ColumnReader(IStreamProvider streamProvider, string columnPath, CachingOption option) { _columnPath = columnPath; _streamProvider = streamProvider; _bytesReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), Path.Combine(columnPath, "V.s.bin"), option, typeof(String8ColumnReader)); _positionsReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(int), Path.Combine(columnPath, "Vp.i32.bin"), option, typeof(String8ColumnReader)); }
public static IColumnReader Wrap(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option) { // Build an (optional) reader for the row indices (will be null if the 'VR.u8.bin' file isn't there) IColumnReader rowIndexReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), Path.Combine(columnPath, EnumWriter.RowIndexFileName), option, typeof(EnumReader)); // Build a reader for the values (require caching if we we have row indices) IColumnReader valueReader = TypeProviderFactory.GetColumnReader(streamProvider, columnType, columnPath, (rowIndexReader != null ? CachingOption.Always : option), typeof(EnumReader)); // If there were row indices, wrap the column. Otherwise, return as-is. if (rowIndexReader != null) { return(new EnumReader(valueReader, rowIndexReader)); } return(valueReader); }
public static void AddCarterCaching(this IServiceCollection services, CachingOption cachingOptions) { services.AddSingleton(cachingOptions); services.AddSingleton <ICarterCachingService, CarterCachingService>(); }
public IColumnReader BinaryReader(IStreamProvider streamProvider, string columnPath, CachingOption option) { return(ColumnCache.Instance.GetOrBuild(columnPath, option, () => { string filePath = ValuesFilePath(columnPath); if (!streamProvider.UncachedExists(filePath)) { return null; } return new PrimitiveArrayReader <T>(streamProvider.OpenRead(filePath)); })); }
public static IColumnReader Wrap(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option) { // Get the underlying value column IColumnReader valueReader = TypeProviderFactory.TryGetColumnReader(streamProvider, columnType, columnPath, option, typeof(NullableReader)); if (valueReader == null) { return(null); } // Get a null reader (or null if there's no nulls file) string nullsPath = Path.Combine(columnPath, "Vn.b8.bin"); IColumnReader nullReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(bool), nullsPath, option, typeof(NullableReader)); // If there are nulls, wrap in a NullableReader if (nullReader != null) { return(new NullableReader(valueReader, nullReader)); } // If not, return the underlying reader unwrapped return(valueReader); }
public static IColumnReader TryGetColumnReader(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option = CachingOption.AsConfigured, Type callingType = null) { // IColumnReaders are nested within each other. Each layer uses this factory method, which uses callingType to return the correct next layer down. // EnumColumnReader -> NullableReader -> PrimitiveReader // EnumColumnReader -> NullableReader -> String8Reader -> PrimitiveReader [byte and position] if (callingType == null) { return(EnumReader.Wrap(streamProvider, columnType, columnPath, option)); } else if (callingType == typeof(EnumReader)) { return(NullableReader.Wrap(streamProvider, columnType, columnPath, option)); } else // typeof(NullableReader) || typeof(String8ColumnReader) || typeof(VariableIntegerReader) { return(Get(columnType).BinaryReader(streamProvider, columnPath, option)); } }
public IColumnReader BinaryReader(IStreamProvider streamProvider, string columnPath, CachingOption requireCached) { // Cache the converted TimeSpan, not the inner long return(ColumnCache.Instance.GetOrBuild(columnPath, requireCached, () => { return ConvertingReader.Build( TypeProviderFactory.Get(typeof(long)).BinaryReader(streamProvider, columnPath, CachingOption.Never), TypeConverterFactory.GetConverter(typeof(long), typeof(TimeSpan))); })); }
public static IColumnReader GetColumnReader(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option = CachingOption.AsConfigured, Type callingType = null) { IColumnReader reader = TryGetColumnReader(streamProvider, columnType, columnPath, option, callingType); if (reader == null) { throw new ColumnDataNotFoundException($"Column data not found at '{columnPath}'.", columnPath); } return(reader); }