protected override void SetCache(IBlobLocation location, MyDocument document)
 {
     _cache.Set(
         location.ContainerName + "#" + location.Path,
         document,
         new CacheItemPolicy {
         SlidingExpiration = TimeSpan.FromMinutes(1)
     });
 }
        protected override void RemoveCache(IBlobLocation location)
        {
            var prefix = location.ContainerName + "#" + location.Path;
            var items  = _cache.Where(p => p.Key.StartsWith(prefix)).ToList();

            foreach (var item in items)
            {
                _cache.Remove(item.Key);
            }
        }
예제 #3
0
 /// <summary>
 /// List the blob names of all blobs matching the provided blob name prefix.
 /// </summary>
 /// <remarks>
 /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para>
 /// </remarks>
 public static IEnumerable <T> ListBlobNames <T>(this IBlobStorageProvider provider, IBlobLocation locationPrefix) where T : UntypedBlobName
 {
     return(provider.ListBlobNames(locationPrefix.ContainerName, locationPrefix.Path)
            .Select(UntypedBlobName.Parse <T>));
 }
예제 #4
0
 /// <summary>
 /// Updates a blob if it already exists.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The provided lambdas can be executed multiple times in case of
 /// concurrency-related retrials, so be careful with side-effects
 /// (like incrementing a counter in them).
 /// </para>
 /// <para>This method is idempotent if and only if the provided lambdas are idempotent.</para>
 /// </remarks>
 /// <returns>The value returned by the lambda, or empty if the blob did not exist.</returns>
 public static Maybe <T> UpdateBlobIfExist <T>(this IBlobStorageProvider provider, IBlobLocation location, Func <T, T> update, IDataSerializer serializer = null)
 {
     return(provider.UpsertBlobOrSkip(location.ContainerName, location.Path, () => Maybe <T> .Empty, t => update(t), serializer));
 }
예제 #5
0
 public static void PutBlob <T>(this IBlobStorageProvider provider, IBlobLocation location, T item, IDataSerializer serializer = null)
 {
     provider.PutBlob(location.ContainerName, location.Path, item, serializer);
 }
예제 #6
0
 public static Maybe <T> GetBlob <T>(this IBlobStorageProvider provider, IBlobLocation location, IDataSerializer serializer = null)
 {
     return(provider.GetBlob <T>(location.ContainerName, location.Path, serializer));
 }
예제 #7
0
 /// <summary>
 /// Deletes a blob if it exists.
 /// </summary>
 /// <remarks>
 /// <para>This method is idempotent.</para>
 /// </remarks>
 public static bool DeleteBlobIfExist(this IBlobStorageProvider provider, IBlobLocation location)
 {
     return(provider.DeleteBlobIfExist(location.ContainerName, location.Path));
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlobLocation"/> class,
 /// pointing to the same location (copy) as the provided location.
 /// </summary>
 public BlobLocation(IBlobLocation fromLocation)
 {
     ContainerName = fromLocation.ContainerName;
     Path          = fromLocation.Path;
 }
예제 #9
0
 public static Task <BlobWithETag <T> > UpsertBlobAsync <T>(this IBlobStorageProvider provider, IBlobLocation location,
                                                            Func <T> insert, Func <T, T> update, CancellationToken cancellationToken, IDataSerializer serializer = null)
 {
     return(provider.UpsertBlobOrSkipAsync <T>(location.ContainerName, location.Path, () => insert(), t => update(t), cancellationToken, serializer));
 }
예제 #10
0
 public static Task <string> PutBlobAsync <T>(this IBlobStorageProvider provider, IBlobLocation location, T item, bool overwrite, IDataSerializer serializer = null)
 {
     return(provider.PutBlobAsync(location.ContainerName, location.Path, item, typeof(T), overwrite, null, CancellationToken.None, serializer));
 }
 public static bool PutBlobStream(this IBlobStorageProvider provider, IBlobLocation location, Stream stream, bool overwrite)
 {
     return(provider.PutBlobStream(location.ContainerName, location.Path, stream, overwrite));
 }
 public static void PutBlobStream(this IBlobStorageProvider provider, IBlobLocation location, Stream stream)
 {
     provider.PutBlobStream(location.ContainerName, location.Path, stream);
 }
 public static Maybe <Stream> GetBlobOffsetStream(this IBlobStorageProvider provider, IBlobLocation location, long offsetBytes, long lengthBytes, out string etag)
 {
     return(provider.GetBlobOffsetStream(location.ContainerName, location.Path, offsetBytes, lengthBytes, out etag));
 }
 public static Maybe <Stream> GetBlobStream(this IBlobStorageProvider provider, IBlobLocation location, out string etag)
 {
     return(provider.GetBlobStream(location.ContainerName, location.Path, out etag));
 }
예제 #15
0
 /// <summary>
 /// Override this method to plug in your cache provider, if needed.
 /// By default, no caching is performed.
 /// </summary>
 protected virtual void SetCache(IBlobLocation location, TDocument document)
 {
 }
예제 #16
0
 public static Task <BlobWithETag <T> > UpsertBlobOrDeleteAsync <T>(this IBlobStorageProvider provider, IBlobLocation location,
                                                                    Func <Maybe <T> > insert, Func <T, Maybe <T> > update, CancellationToken cancellationToken, IDataSerializer serializer = null)
 {
     return(provider.UpsertBlobOrDeleteAsync(location.ContainerName, location.Path, insert, update, cancellationToken, serializer));
 }
예제 #17
0
 /// <summary>
 /// Override this method to plug in your cache provider, if needed.
 /// By default, no caching is performed.
 /// </summary>
 protected virtual void RemoveCache(IBlobLocation location)
 {
 }
예제 #18
0
 public static Task <BlobWithETag <T> > UpdateBlobIfExistAsync <T>(this IBlobStorageProvider provider, IBlobLocation location,
                                                                   Func <T, T> update, IDataSerializer serializer = null)
 {
     return(provider.UpsertBlobOrSkipAsync(location.ContainerName, location.Path, () => Maybe <T> .Empty, t => update(t), CancellationToken.None, serializer));
 }
예제 #19
0
 /// <summary>
 /// List and get all blobs matching the provided blob name prefix.
 /// </summary>
 /// <remarks>
 /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para>
 /// </remarks>
 public static IEnumerable <T> ListBlobs <T>(this IBlobStorageProvider provider, IBlobLocation locationPrefix, int skip = 0, IDataSerializer serializer = null)
 {
     return(provider.ListBlobs <T>(locationPrefix.ContainerName, locationPrefix.Path, skip, serializer));
 }
예제 #20
0
 public static Task <BlobWithETag <T> > UpdateBlobIfExistOrDeleteAsync <T>(this IBlobStorageProvider provider, IBlobLocation location,
                                                                           Func <T, Maybe <T> > update, IDataSerializer serializer = null)
 {
     return(provider.UpdateBlobIfExistOrDeleteAsync(location.ContainerName, location.Path, update, CancellationToken.None, serializer));
 }
예제 #21
0
 /// <summary>
 /// Delete all blobs matching the provided blob name prefix.
 /// </summary>
 /// <remarks>
 /// <para>This method is idempotent.</para>
 /// </remarks>
 public static void DeleteAllBlobs(this IBlobStorageProvider provider, IBlobLocation locationPrefix)
 {
     provider.DeleteAllBlobs(locationPrefix.ContainerName, locationPrefix.Path);
 }
예제 #22
0
 public static Task <BlobWithETag <T> > GetBlobAsync <T>(this IBlobStorageProvider provider, IBlobLocation location, IDataSerializer serializer = null)
 {
     return(provider.GetBlobAsync <T>(location.ContainerName, location.Path, CancellationToken.None, serializer));
 }
예제 #23
0
 public static string GetBlobEtag(this IBlobStorageProvider provider, IBlobLocation location)
 {
     return(provider.GetBlobEtag(location.ContainerName, location.Path));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlobLocation"/> class,
 /// pointing to the same location (copy) as the provided location.
 /// </summary>
 public BlobLocation(IBlobLocation fromLocation)
 {
     ContainerName = fromLocation.ContainerName;
     Path = fromLocation.Path;
 }
예제 #25
0
 public static bool PutBlob <T>(this IBlobStorageProvider provider, IBlobLocation location, T item, bool overwrite, IDataSerializer serializer = null)
 {
     return(provider.PutBlob(location.ContainerName, location.Path, item, overwrite, serializer));
 }
예제 #26
0
 protected void DeleteAllInternal(IBlobLocation prefix)
 {
     RemoveCache(prefix);
     Blobs.DeleteAllBlobs(prefix);
 }
예제 #27
0
 /// <summary>
 /// Inserts or updates a blob depending on whether it already exists or not.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The provided lambdas can be executed multiple times in case of
 /// concurrency-related retrials, so be careful with side-effects
 /// (like incrementing a counter in them).
 /// </para>
 /// <para>
 /// This method is idempotent if and only if the provided lambdas are idempotent
 /// and if the object returned by the insert lambda is an invariant to the update lambda
 /// (if the second condition is not met, it is idempotent after the first successful call).
 /// </para>
 /// </remarks>
 /// <returns>The value returned by the lambda.</returns>
 public static T UpsertBlob <T>(this IBlobStorageProvider provider, IBlobLocation location, Func <T> insert, Func <T, T> update, IDataSerializer serializer = null)
 {
     return(provider.UpsertBlobOrSkip <T>(location.ContainerName, location.Path, () => insert(), t => update(t), serializer).Value);
 }
예제 #28
0
 /// <summary>
 /// Override this method to plug in your cache provider, if needed.
 /// By default, no caching is performed.
 /// </summary>
 protected virtual bool TryGetCache(IBlobLocation location, out TDocument document)
 {
     document = default(TDocument);
     return(false);
 }
예제 #29
0
 /// <summary>
 /// List the blob locations of all blobs matching the provided blob name prefix.
 /// </summary>
 /// <remarks>
 /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para>
 /// </remarks>
 public static IEnumerable <IBlobLocation> ListBlobLocations(this IBlobStorageProvider provider, IBlobLocation blobLocationPrefix)
 {
     return(provider.ListBlobNames(blobLocationPrefix.ContainerName, blobLocationPrefix.Path)
            .Select(name => new BlobLocation(blobLocationPrefix.ContainerName, name)));
 }
 protected override bool TryGetCache(IBlobLocation location, out MyDocument document)
 {
     return(null != (document = _cache.Get(location.ContainerName + "#" + location.Path) as MyDocument));
 }