Skip to content

Commit

Permalink
Cache client
Browse files Browse the repository at this point in the history
  • Loading branch information
twsouthwick committed Sep 18, 2020
1 parent d51b618 commit f33d166
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions WWTWebservices.Azure/AzurePlateTilePyramid.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
using Azure.Core;
using Azure.Storage.Blobs;
using System;
using System.Collections.Concurrent;
using System.IO;

namespace WWTWebservices.Azure
{
public class AzurePlateTilePyramid : IPlateTilePyramid
{
private readonly ConcurrentDictionary<string, BlobContainerClient> _containers;
private readonly TokenCredential _credentials;
private readonly string _storageUri;

public AzurePlateTilePyramid(string storageUri, TokenCredential credentials)
{
_credentials = credentials;
_storageUri = storageUri;
_containers = new ConcurrentDictionary<string, BlobContainerClient>();
}

public Stream GetStream(string plateName, int level, int x, int y)
{
var name = Path.GetFileNameWithoutExtension(plateName).ToLowerInvariant();
var uri = new Uri($"{_storageUri}/{name}");
var container = new BlobContainerClient(uri, _credentials);
var container = _containers.GetOrAdd(plateName, c =>
{
var name = Path.GetFileNameWithoutExtension(plateName).ToLowerInvariant();
var uri = new Uri($"{_storageUri}/{name}");

return new BlobContainerClient(uri, _credentials);
});

var client = container.GetBlobClient($"L{level}X{x}Y{y}.png");
var download = client.Download();

Expand Down

0 comments on commit f33d166

Please sign in to comment.