public static Task SetWithVersionAsync <T>(this IDistributedCache cache, string key, T item, CacheVersion cacheVersion, DistributedCacheEntryOptions?options = default, ILogger?logger = default, CancellationToken cancellationToken = default) where T : class { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } if (item == null) { throw new ArgumentNullException(nameof(item)); } return(SetWithVersionInternalAsync(cache, key, item, cacheVersion, options, logger, cancellationToken)); }
private static async Task SetWithVersionInternalAsync <T>(IDistributedCache cache, string key, T item, CacheVersion cacheVersion, DistributedCacheEntryOptions?options = default, ILogger?logger = default, CancellationToken cancellationToken = default) where T : class { string json = JsonConvert.SerializeObject(new VersionedJson <T> { Instance = item, Version = cacheVersion.Version }); try { if (options is { }) { await cache.SetStringAsync(key, json, options, cancellationToken); return; } await cache.SetStringAsync(key, json, cancellationToken); }