Exemplo n.º 1
0
        public async void SmokeTestSyncMissHit()
        {
            var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}");

            Directory.CreateDirectory(path);
            AsyncCache cache = null;

            try
            {
                var asyncCacheOptions = new AsyncCacheOptions()
                {
                    MaxQueuedBytes = 0
                };
                var builder = new HashBasedPathBuilder(path,
                                                       8192, '/', ".jpg");

                cache = new AsyncCache(asyncCacheOptions, new NullCacheManager(), builder, null);

                var keyBasis = new byte[] { 6, 1, 2 };
                var result   = await cache.GetOrCreateBytes(keyBasis, (token) =>
                {
                    return(Task.FromResult(new Tuple <string, ArraySegment <byte> >(
                                               null, new ArraySegment <byte>(new byte[] { 3, 2, 1 }))));
                },
                                                            CancellationToken.None, false);

                Assert.NotNull(result.Data);
                Assert.Equal("WriteSucceeded", result.Status);

                await cache.AwaitEnqueuedTasks();

                var result2 = await cache.GetOrCreateBytes(keyBasis, (token) =>
                {
                    return(Task.FromResult(new Tuple <string, ArraySegment <byte> >(
                                               null, new ArraySegment <byte>(new byte[] { 3, 2, 1 }))));
                },
                                                           CancellationToken.None, false);

                Assert.NotNull(result2.Data);
                Assert.Equal("DiskHit", result2.Status);
                var hash = builder.HashKeyBasis(keyBasis);
                var expectedPhysicalPath = builder.GetPhysicalPathFromHash(hash);
                Assert.True(File.Exists(expectedPhysicalPath));
            }
            finally
            {
                try
                {
                    await cache?.AwaitEnqueuedTasks();
                }
                finally
                {
                    Directory.Delete(path, true);
                }
            }
        }
Exemplo n.º 2
0
 public HybridCacheOptions(string physicalCacheDir)
 {
     PhysicalCacheDir      = physicalCacheDir;
     AsyncCacheOptions     = new AsyncCacheOptions();
     CleanupManagerOptions = new CleanupManagerOptions();
 }