I am trying implement Using local storage with BLOB storage .
I went through http://allcomputers.us/windows_azure/using-local-storage-with-blob-storage-(part-1)—using-a-local-cache—defining-and-accessing-local-storage.aspx
and re factored my GetBlob method as below .
public Stream GetBlob(string blobAddress, string CONTAINER_NAME)
{
MemoryStream stream = null;
stream = CheckInLocalCache(blobAddress);
if (stream==null)
{
CloudBlobContainer container = Client.GetContainerReference(CONTAINER_NAME);
if (container != null)
{
stream = new MemoryStream();
container.GetBlobReference(blobAddress).DownloadToStream(stream);
}
}
return stream;
}
private static MemoryStream CheckInLocalCache(string blobAddress)
{
MemoryStream localBlobStream=null;
LocalResource localBlobCache = RoleEnvironment.GetLocalResource("localBlobCache");
if (localBlobCache != null)
{
string localCacheRootDirectory = localBlobCache.RootPath;
string blobName = blobAddress.Split('/')[blobAddress.Split('/').Length - 1];
if (File.Exists(localBlobCache.RootPath + blobName))
{
localBlobStream = new MemoryStream(File.ReadAllBytes(localBlobCache.RootPath + blobName));
}
}
return localBlobStream;
}
In Config file i added this
<WebRole name="ServiceRuntimeWebsite">
<LocalResources>
<LocalStorage name="localBlobCache"
cleanOnRoleRecycle="true"
sizeInMB="100" />
</LocalResources>
</WebRole>
When i run my prject in development environment , i see the folder “localBlobCache” is created . But even after many times loading blobs from azure it never really loaded to my local storage . Can anyone tell Whats wrong ?
It doesn’t look like anything in the code you shared saves the file to the cache directory. You probably want something in GetBlob that saves the blob to a file if it isn’t already there.