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() |
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.
Note
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.
0 comentarios:
Publicar un comentario