lunes, 25 de julio de 2011

CloudDrive.InitializeCache Method (Multiples Conecciones)

 

 

 

Initializes the optional read cache for any subsequently mounted drives associated with the role instance.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.CloudDrive (in microsoft.windowsazure.clouddrive.dll)

  Usage

Visual Basic

Dim cachePath As String
Dim totalCacheSize As Integer

CloudDrive.InitializeCache(cachePath, totalCacheSize)

  Syntax

Visual Basic

Public Shared Sub InitializeCache ( _
cachePath As String, _
totalCacheSize As Integer _
)

C#

public static void InitializeCache (
string cachePath,
int totalCacheSize
)

C++

public:
static void InitializeCache (
String^ cachePath,
int totalCacheSize
)

J#

public static void InitializeCache (
String cachePath,
int totalCacheSize
)

JScript

public static function InitializeCache (
cachePath : String,
totalCacheSize : int
)

Parameters


cachePath

The local file system path to the directory containing the cache.



totalCacheSize

The total cache size, in megabytes.


  Example

The following snippet from a ServiceDefinition.csdef file specifies a local resource named LocalDriveCache.






<LocalResources>
     <LocalStorage name="LocalDriveCache" sizeInMB="2048" cleanOnRoleRecycle="false" />
</LocalResources>
 

The following code example creates and mounts three drives, allocating cache space to the first two and none to the third.

C#





public void InitializeDriveCache()
{
// Get a reference to the local resource.
LocalResource localResource = RoleEnvironment.GetLocalResource("LocalDriveCache");

// Initialize the drive cache.
CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes);

// Use the storage emulator.
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;

// Create the Blob service client.
CloudBlobClient client = storageAccount.CreateCloudBlobClient();

// Create the container for the drive if it does not already exist.
CloudBlobContainer container = new CloudBlobContainer("mydrives", client);
container.CreateIfNotExist();

int cacheSize = (int)Math.Round((double)localResource.MaximumSizeInMegabytes / 2;

// Create and mount three drives, allocating portions of the cache
// to the first two and none to the third.
CloudDrive drive1 = new CloudDrive(container.GetPageBlobReference("myvhd_A").Uri, storageAccount.Credentials);
drive1.Create(500);
drive1.Mount(cacheSize, DriveMountOptions.None);

CloudDrive drive2 = new CloudDrive(container.GetPageBlobReference("myvhd_B").Uri, storageAccount.Credentials);
drive2.Create(500);
drive2.Mount(cacheSize, DriveMountOptions.None);

CloudDrive drive3 = new CloudDrive(container.GetPageBlobReference("myvhd_C").Uri, storageAccount.Credentials);
drive3.Create(500);
drive3.Mount(0, DriveMountOptions.None);

// List each drive letter and associated page blob.
foreach (var item in CloudDrive.GetMountedDrives())
{
System.Diagnostics.Debug.WriteLine("Drive letter: " + item.Key);
System.Diagnostics.Debug.WriteLine("Page blob URI: " + item.Value);
}
}

 

  Remarks

A role instance running in Windows Azure may have an optional write-through cache for all drives that are mounted by the instance. Each role instance may allocate a single cache. The InitializeCache method allocates total cache space for all drives mounted by the role instance. When a given drive is mounted, you can choose to allocate a portion of the total cache space to that drive. If you intend to allocate cache space for a given drive, you must call InitializeCache before you mount the drive. When you call InitializeCache, be sure to take into account the total cache size you expect to need for all drives to be mounted.

Note that you can also mount a drive with no cache specified. If you opt not to allocate cache space for a drive, then it's not necessary to call InitializeCache.

The local file system path specified for the cachePath parameter should be the root path for a local storage resource defined in the service definition file. A local storage resource reserves space on the local file system for the role instance to use at runtime. See How to Configure Local Storage Resources for details on declaring a local storage resource for the cache. Note that when you define the local storage resource for the cache, you should set the CleanOnRoleRecycle attribute to false, so that the cache data persists when the role is recycled.

noteNote

Data in the cache may not be persisted in the event of a transient hardware failure that requires the role instance to be moved to different hardware in Windows Azure.

The maximum size permitted for the local storage resource depends on the size of the VM allocated for the role instance. The VM size is specified in the service definition file. For details on choosing a VM size and the amount of available local storage space for each, see How to Configure Virtual Machine Sizes. Note that the local storage space allocated to the VM is the total amount for the instance, so the total space allocated for all local storage resources, including the drive cache, must not exceed the total allowed for the VM.

To initialize the cache, return a reference to the local storage resource by calling the GetLocalResource method, then use the values returned by the RootPath and MaximumSizeInMegaBytes properties of the local resource to initialize the cache:

LocalResource localCache = RoleEnvironment.GetLocalResource("MyAzureDriveCache");
CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);

If your code calls InitializeCache each time the role instance starts, it's recommended that you initialize the cache with the same parameters each time.

 


 


link http://207.46.16.248/en-us/library/microsoft.windowsazure.storageclient.clouddrive.initializecache.aspx

0 comentarios:

Publicar un comentario