Пример #1
0
        public static void ByteArrayBindingCacheHit(
            [Blob(ContainerName + "/" + InputBlobName, FileAccess.Read)] ICacheAwareReadObject blob)
        {
            Assert.IsTrue(blob.IsCacheHit);

            SharedMemoryMetadata cacheObj = blob.CacheObject;

            Assert.NotNull(cacheObj);

            _numCacheHits = 1;
        }
Пример #2
0
        public static async Task ByteArrayBindingCacheMissAsync(
            [Blob(ContainerName + "/" + InputBlobName, FileAccess.Read)] ICacheAwareReadObject blob)
        {
            Assert.IsFalse(blob.IsCacheHit);

            using (Stream blobStream = blob.BlobStream)
                using (StreamReader reader = new StreamReader(blobStream))
                {
                    string result = await reader.ReadToEndAsync();

                    Assert.AreEqual(TestData, result);
                    _numCacheMisses = 1;
                }
        }
        /// <summary>
        /// Binds the object based on the given <see cref="BindingContext"/> in a manner that is aware of the presence of <see cref="IFunctionDataCache"/>.
        /// This means that before reading an object, it will be attempted to be read from the cache. When writing, it will be attempted to be written to the cache.
        /// In case of a read access (i.e., <see cref="FileAccess.Read"/>), the binding may be delayed as the object could be read either from the cache or storage.
        /// The actual conversion is thus delayed to <see cref="RpcSharedMemoryDataExtension"/>.
        /// </summary>
        internal static async Task BindCacheAwareAsync(BindingContext context, FileAccess access)
        {
            if (access == FileAccess.Write)
            {
                ICacheAwareWriteObject obj = await context.Binder.BindAsync <ICacheAwareWriteObject>(context.Attributes);

                if (context.Value is SharedMemoryObject sharedMemoryObj)
                {
                    using (Stream sharedMemoryStream = sharedMemoryObj.Content)
                        using (Stream blobStream = obj.BlobStream)
                        {
                            await sharedMemoryStream.CopyToAsync(blobStream);

                            await blobStream.FlushAsync();
                        }
                }
                else
                {
                    throw new NotSupportedException($"Cannot perform cache-aware binding of write object with type: {context.Value.GetType()}");
                }

                context.Value = obj;
            }
            else if (access == FileAccess.Read)
            {
                ICacheAwareReadObject obj = await context.Binder.BindAsync <ICacheAwareReadObject>(context.Attributes);

                // We get a binding to the object. It could either be read from the cache or from storage.
                // Therefore, we delay the conversion into the actual object to the RpcSharedMemoryDataExtension.
                // The extension will check if the object was already in the cache, then no conversion is necessary.
                // If the object was not in the cache then it will be read directly into shared memory without creating extra
                // intermediate copies.
                context.Value = obj;
            }
            else
            {
                throw new NotSupportedException($"FileAccess: {access} not supported in CacheAware mode");
            }
        }
Пример #4
0
 public static void ByteArrayBindingCacheHitVerifyFunctionDataCacheKey(
     [Blob(ContainerName + "/" + InputBlobName, FileAccess.Read)] ICacheAwareReadObject blob)
 {
     Assert.AreEqual(_expectedBlobCacheKey, blob.CacheKey);
 }