public async Task CacheContent <T>(string key, T content, ICacheInfo cacheInfo) { using (var ms = new MemoryStream()) using (var sw = new StreamWriter(ms)) using (var jw = new JsonTextWriter(sw)) { var serializer = new JsonSerializer(); var now = DateTime.UtcNow; serializer.ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }; serializer.Serialize(jw, content); await sw.FlushAsync(); var putReq = new PutObjectRequest { BucketName = BucketName, Key = key, ContentType = "application/json", // We use the StreamWriter BaseStream, as apparently using a // MemoryStream breaks this part and only uploads an initial partial // segment of the data? F**k knows InputStream = sw.BaseStream, }; putReq.Metadata["content-expiration"] = cacheInfo.ExpiresAt?.ToISOString(); putReq.Metadata["content-creation"] = cacheInfo.CachedAt.ToISOString(); putReq.Metadata["content-hash"] = Sha256.HashContent(ms).ToHexString(); await Client.PutObjectAsync(putReq); } }
public Task SetAsync <T>(T queryResult, ICacheInfo cacheInfo, Func <TCacheEntryOptions> getCacheEntryOptions) { #if NETSTANDARD1_3 || NET46 return(Task.CompletedTask); #else return(Task.FromResult(0)); #endif }
public CategoriesService( IRepository <CategoryInfo, int> repository, IEventBus eventBus, ICacheInfo cacheManager) : base(repository, eventBus) { this.cacheManager = cacheManager; }
static void Main(string[] args) { //Retrieve Cached object from market information cache server which is locally hosted ICacheInfo remoteCache = (ICacheInfo)Activator.GetObject(typeof(ICacheInfo), "ipc://InfoCacheServer/MktInfoCacheImpl.rem"); DataSet cacheObj = remoteCache.RetrieveCache(); Console.WriteLine("Information Successfully Retrieved..."); Console.ReadLine(); }
private CacheEntry Cast(ICacheInfo value) { var match = Regex.Match(value.Name, "(.*)\\[(.*)\\]$"); if (match != null && match.Success) { var prefix = match.Groups[1].Value; var type = match.Groups[2].Value; if (prefix == "core" || prefix == "master" || prefix == "web") { return(new DatabaseCacheEntry(value.Count, value.Id.ToString(), value.Name, value.Size, value.RemainingSpace) { Enabled = value.Enabled, MaxSize = value.MaxSize, Scavengable = value.Scavengable, Database = prefix, Type = type }); } else { return(new SiteCacheEntry(value.Count, value.Id.ToString(), value.Name, value.Size, value.RemainingSpace) { Enabled = value.Enabled, MaxSize = value.MaxSize, Scavengable = value.Scavengable, Site = prefix, Type = type }); } } match = Regex.Match(value.Name, "(.*) - Prefetch data\\((.*)\\)$"); if (match != null && match.Success) { var providerType = match.Groups[1].Value; var database = match.Groups[2].Value; return(new DatabaseCacheEntry(value.Count, value.Id.ToString(), value.Name, value.Size, value.RemainingSpace) { Enabled = value.Enabled, MaxSize = value.MaxSize, Scavengable = value.Scavengable, Database = database, Type = $"{providerType} - Prefetch data" }); } return(new CacheEntry(value.Count, value.Id.ToString(), value.Name, value.Size, value.RemainingSpace) { Enabled = value.Enabled, MaxSize = value.MaxSize, Scavengable = value.Scavengable }); }
public CompilerCacheBase(string cacheFolder) : this() { Logging.Emit("setting up file stores"); if (string.IsNullOrEmpty(cacheFolder)) throw new ArgumentNullException("cacheFolder"); outputCache = FileCacheStore.Load(Path.Combine(cacheFolder, "outputs")); includeCache = FileCacheStore.Load(Path.Combine(cacheFolder, "includes")); Logging.Emit("setup cache info"); stats = new CacheInfo(outputCache); Logging.Emit("setup hasher"); hasher = new HashUtil(includeCache); }
public CompilerCacheBase(string cacheFolder) : this() { Logging.Emit("setting up file stores"); if (string.IsNullOrEmpty(cacheFolder)) { throw new ArgumentNullException("cacheFolder"); } outputCache = FileCacheStore.Load(Path.Combine(cacheFolder, "outputs")); includeCache = FileCacheStore.Load(Path.Combine(cacheFolder, "includes")); Logging.Emit("setup cache info"); stats = new CacheInfo(outputCache); Logging.Emit("setup hasher"); hasher = new HashUtil(includeCache); }
/// <summary> /// Creates a new CacheInfo based on a resource that implements ICacheInfo /// </summary> /// <param name="cachedAt">The time the resource was cached.</param> /// <param name="cacheExpiration">How long until the resource will expire.</param> public CacheInfo(ICacheInfo cacheInfo) { CachedAt = cacheInfo.CachedAt; ExpiresAt = cacheInfo.ExpiresAt; }
public T Get <T>(Func <T> executeQuery, ICacheInfo cacheInfo, Func <TCacheEntryOptions> getCacheEntryOptions) => executeQuery();
public void Set <T>(T queryResult, ICacheInfo cacheInfo, Func <TCacheEntryOptions> getCacheEntryOptions) { }
public Task <T> GetAsync <T>(Func <Task <T> > executeQueryAsync, ICacheInfo cacheInfo, Func <TCacheEntryOptions> getCacheEntryOptions) => executeQueryAsync();
public SitecoreCacheMetric(ICacheInfo cache) : this(cache.Name, cache.Count, cache.Size) { }