/// <summary> /// Write a cache data to the cache store. /// </summary> public async Task WriteAsync(MetadataService service, ConsumerRequest request, Metadata metadata) { var u = request.Url.ToString(); if (metadata == null) { await _Cache.RemoveAsync(u).ConfigureAwait(false); } else { using (var ms = new MemoryStream()) { XamlServices.Save(ms, metadata); await _Cache.SetAsync(u, ms.ToArray()).ConfigureAwait(false); } } }
/// <summary> /// Writes the <see cref="Metadata" /> to to the cache store. /// </summary> public async Task WriteAsync(MetadataService service, ConsumerRequest request, Metadata metadata) { if (metadata == null) { _Cache.Remove(request.Url); } else { _Cache.Set(request.Url, metadata, new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromMinutes(60) }); } if (_Distributed != null) { await _Distributed.WriteAsync(service, request, metadata).ConfigureAwait(false); } }
/// <summary> /// Reads the cached <see cref="Metadata" /> for the URL of <paramref name="request"/>. /// </summary> /// <param name="service">The <see cref="MetadataService" /> reading cache.</param> /// <param name="request">The consumer request.</param> /// <returns>The task object representing the asynchronous operation. /// The <see cref="Task{TResult}.Result"/> property on the task object returns a cached <see cref="Metadata"/>.</returns> public async Task <Metadata> ReadAsync(MetadataService service, ConsumerRequest request) { if (!_Cache.TryGetValue(request.Url, out Metadata r)) { if (_Distributed != null) { r = await _Distributed.ReadAsync(service, request).ConfigureAwait(false); if (r != null) { _Cache.Set(request.Url, r, new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromMinutes(60) }); } } } return(r); }
/// <summary> /// Initializes a new instance of the <see cref="HttpMetadataHandler" /> class. /// </summary> public HttpMetadataHandler(ILoggerFactory loggerFactory, MetadataService service) { _Logger = loggerFactory.CreateLogger <HttpMetadataHandler>(); _Service = service; }