我正在尝试实现 Using local storage with BLOB storage 。我浏览了http://allcomputers.us/windows_azure/using-local-storage-with-blob-storage-(part-1)---using-a-local-cache---defining-and-accessing-local -storage.aspx 并重构了我的 GetBlob 方法,如下所示。
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;
}
在配置文件中我添加了这个
<WebRole name="ServiceRuntimeWebsite">
<LocalResources>
<LocalStorage name="localBlobCache"
cleanOnRoleRecycle="true"
sizeInMB="100" />
</LocalResources>
</WebRole>
当我在开发环境中运行我的项目时,我看到文件夹“localBlobCache”被创建。但即使在多次从 azure 加载 blob 之后,它也从未真正加载到我的本地存储中。谁能告诉我怎么了?