Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Using local storage with BLOB storage (part 1) - Using a local cache & Defining and accessing local storage

3/8/2011 9:29:53 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
IYou used a file handler to intercept MP3 requests from your website and to serve them from BLOB storage rather than from your website. A more efficient approach would be to check whether the file is already on your local filesystem. If the file already exists, then you can just serve the file straight up. If the file doesn’t exist, you can retrieve it from BLOB storage, store it on the local filesystem, and then serve the file. All future requests for the file won’t need to continually retrieve the file from BLOB storage.

1. Using a local cache

When you define Windows Azure web roles, you can allocate a portion of the local filesystem for use as a temporary cache. This local storage area allows you to store semi-persistent data that you might use frequently, without having to continually re-request or recalculate the data for every call.

You must be aware that this local storage area isn’t shared across multiple instances and the current instance of your web role is the only one that can access that data. Figure 1 shows the distribution of BLOBs in local storage across multiple instances.

Figure 1. Three web role instances, each with different local copies of BLOBs in its local storage


Because the load balancer evenly distributes requests across instances, a user won’t always be served by the same web role instance. Any data that you need persisted across multiple requests (such as shopping cart or session data) shouldn’t be stored in local storage and must be stored in a data store that all instances can access.

2. Defining and accessing local storage

You can define how much space you require on your local filesystem in your service definition file. The FC uses this information to assign your web role to a host with enough disk space. The following code is how you would define that you need 100 MB of space to cache MP3 files:

<WebRole name="ServiceRuntimeWebsite">
<LocalResources>
<LocalStorage name="mp3Cache"
cleanOnRoleRecycle="true"
sizeInMB="100" />
</LocalResources>
</WebRole>

To access any of the files held in local storage, you can use the following code to retrieve the location of the file:

 LocalResource localCache =
RoleEnvironment.GetLocalResource("mp3Cache");

string localCacheRootDirectory = localCache.RootPath;

After you’ve retrieved the root directory of local storage (RootPath), you can use standard .NET filesystem calls to modify, create, read, or delete files held in local storage. 

Great! You’ve configured your local storage area. Now you need to modify your HTTP handler to use your local storage area, where possible.

Other -----------------
- Integrating BLOBs with your ASP.NET websites
- Downloading BLOBs
- Managing BLOBs using the StorageClient library (part 2) - Uploading BLOBs & Deleting BLOBs
- Managing BLOBs using the StorageClient library (part 1) - Listing BLOBs using the storage client
- Using the REST API (part 2) - Authenticating private requests
- Using the REST API (part 1) - Listing BLOBs in a public container using REST
- The basics of BLOBs - Configuring your application to work against the live service
- The basics of BLOBs : Developing against containers (part 3) - Listing containers & Deleting a container
- The basics of BLOBs : Developing against containers (part 2) - Creating a container
- The basics of BLOBs : Developing against containers (part 1) - Accessing the StorageClient library & Accessing development storage
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server