From 09287bceea7b3534d4d319a310ad0e99608a9ac5 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 19 Mar 2024 13:25:58 +0100 Subject: [PATCH] add media metadata cache --- zero/Media/MediaMetadataCache.cs | 57 +++----------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/zero/Media/MediaMetadataCache.cs b/zero/Media/MediaMetadataCache.cs index 2350d52c..1407dfc5 100644 --- a/zero/Media/MediaMetadataCache.cs +++ b/zero/Media/MediaMetadataCache.cs @@ -2,59 +2,10 @@ namespace zero.Media; -public class MediaMetadataCache : IMediaMetadataCache +public sealed class MediaMetadataCache { - private const string PREFIX = "zero/media/"; - - protected IMemoryCache Cache { get; set; } - - - public MediaMetadataCache(IMemoryCache cache) + public IMemoryCache Cache { get; internal set; } = new MemoryCache(new MemoryCacheOptions { - Cache = cache; - } - - - /// - public bool TryGet(string id, out CachedMedia media) - { - MediaCacheEntry entry = Cache.Get(Key(id)); - - media = entry != null ? CachedMedia.Create(entry) : null; - return entry != null; - } - - - /// - public void Set(Media media) - { - MediaCacheEntry entry = MediaCacheEntry.Create(media); - Cache.Set(Key(media.Id), entry, new MemoryCacheEntryOptions() - { - SlidingExpiration = TimeSpan.FromSeconds(60 * 60 * 24) - }); - } - - - /// - /// Generate cache key from media Id - /// - static string Key(string id) - { - return PREFIX + id; - } + SizeLimit = 1000 + }); } - - -public interface IMediaMetadataCache -{ - /// - /// Get a cached and reduced version of a media entity - /// - bool TryGet(string id, out CachedMedia media); - - /// - /// Store a media entity in cache - /// - void Set(Media media); -} \ No newline at end of file