How to: Get Started with a Simple Client (Code) (Velocity)

05/24/2009

When you programmatically configure your cache client, the configuration settings are passed to the DataCacheFactory class constructor.

Note 
For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.

The cache client type is defined by the routingClient parameter in the DataCacheFactory class constructor. For a simple client, the routingClient parameter must be false. For more information about the application configuration settings, see Application Configuration Settings (Velocity).

Note 
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)

To configure a simple client programmatically
Create an array of DataCacheServerEndpoint objects to specify the cache hosts for the client.

Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor.

Select a simple client type by assigning a false value to the routingClient parameter of the DataCacheFactory constructor.

Configure local cache by assigning a true or false value to the localCache parameter of the DataCacheFactory constructor. Use the true value to enable local cache or a false value to disable local cache.

Use the GetCache method to obtain an instance of the routing client.

Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Configuration Code client class datacachefactory constructor configure simple

How to: Get Started with a Routing Client (Code) (Velocity)

05/24/2009

When you programmatically configure your cache client, the configuration settings are passed to the DataCacheFactory class constructor.

Note 
For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.

The cache client type is defined by the routingClient parameter in the DataCacheFactory class constructor. For a routing client, the routingClient parameter must be true. For more information about the application configuration settings, see Application Configuration Settings (Velocity).

Note 
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)

To configure a routing client programmatically
Create an array of DataCacheServerEndpoint objects to specify the cache hosts for the client.

Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor.

Select a routing client type by assigning a true value to the routingClient parameter of the DataCacheFactory constructor.

Configure local cache by assigning a true or false value to the localCache parameter of the DataCacheFactory constructor. Use the true value to enable local cache, or a false value to disable local cache.

Use the GetCache method to obtain an instance of the routing client.

Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Configuration Code client class datacachefactory constructor configure routing

How to: Remove an Object from Cache (Velocity)

05/24/2009

The following examples show the ways you can remove objects from the cache. These procedures assume that you have already set up your cache cluster and have prepared your development environment to write cache-enabled applications. For more information about how to do this, see Installation and Deployment (Velocity) and How to: Prepare the Development Environment (Velocity).

For more details about the methods that are used in these examples, see these class library topics:

Remove

Item

Data in the cache is not encrypted and is available to any cache client with the appropriate configuration settings. We highly recommend that you secure the XML-based application configuration files, if used, to specify the cache client.

To remove an object from the cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.

Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.

Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.

After you have the DataCache object, the Remove method or Item property may be used to remove an object from cache.

Example
The following example uses the Remove method to remove an object from cache.

Note 
There are many other parameters available for this method. See the Remove class library for more information.

C#  Copy Code
//remove object in cache using key "Key0"
myCache.Remove("Key0");

The following example uses the Item property that has array notation to remove an object from cache.

C#  Copy Code
//remove object in cache using array notation
myCache["Key0"] = null;

Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Application client data development environment object datacachefactory remove

How to: Update an Object in Cache (Velocity)

05/24/2009

To update an object in cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.

Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.

Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.

After you have the DataCache object, the Put method or Item property may be used to update an object in cache.

Example
The following example uses the Put method to add an object to cache. If the object is not present when this method is called, it will be added to the cache. If the object is already present, it will be replaced.

Note 
There are many other parameters available for this method. See the Put class library for more information.
C#  Copy Code
//add or replace object in cache using key "Key0"
myCache.Put("Key0", "object replaced or added using Key0");

The following example uses the Item property that has array notation to add an object to cache. If the object is not present when this method is called, it will be added to the cache. If the object is already present, it will be replaced.

C#  Copy Code
//add or replace object in cache using array notation
myCache["Key0"] = "object replaced or added using Key0";

Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Microsoft Application example client method object datacachefactory datacache update

How to: Add an Object to Cache (Velocity)

05/24/2009

The following examples show the ways you can add objects to the cache. These procedures assume that you have already set up your cache cluster and have prepared your development environment to write cache-enabled applications. For more information about how to do this, see Installation and Deployment (Velocity) and How to: Prepare the Development Environment (Velocity).

For more details about the methods that are used in these examples, follow these links to view the class library topics:

Add

Put

Item

Data in the cache is not encrypted and is available to any cache client with the appropriate configuration settings. We highly recommend that you secure the XML-based application configuration files, if used, to specify the cache client.

To add an object to cache
Make sure that the using statement (Imports in Visual Basic) is at the top of your application code to reference the Microsoft.Data.Caching namespace.

Create a DataCacheFactory object that is accessible to all parts of the application that need a cache client. We recommend reusing the same DataCacheFactory object to conserve memory and optimize performance.

Use the DataCacheFactory object to create a DataCache object (also referred to as the cache client) if you have not already done this. In the following examples, the DataCacheFactory instance is called CacheFactory1.

After you have the DataCache object, the Add method, Put method, or Item property may be called to add an object to the cache.

Example
The following example demonstrates how you can use the Add method to add an object to cache. You will get an exception if an object has already been cached by the same key (the first parameter).

Note 
There are many other parameters available for this method. See the Add class library for more information.
C#  Copy Code
//add object to cache with key "Key0"
myCache.Add("Key0", "object added with Key0");

Posted in: C# and .NET| Tags: Velocity CTP CTP 3 .NET 4.0 Cache Application client method development environment object datacachefactory item

Hot Posts

Latest posts

Tags

Others

Sponsors

asp.net interview questions