enterprise

Just another Shot Blogs weblog

CacheManager

January 8th, 2010 · No Comments
Uncategorized

Enterprise Library cache application block allows developers in the application of combination of a local cache, it supports within the memory cache and optional can be stored in database to store or independent backend storage. Application block can not make use of modification, it provides all must gain, add and remove caching data. Configurable expire and remove strategy is also part of the application.
In constructing the enterprise issued by the scope of application, the structure and the developers are faced with many challenges, cache can help them win which includes the following challenges:
Performance. Cache memory data users with the corresponding data as close to improve the performance of the application, it avoids the repeated data processing and transmission of creation,.
Scalability. In the cache memory information to conserve resources and increase in applications demand increase scalability.
Usability. Data stored in a cache, application may fail in the system, such as network latency, surviving Web service problems and hardware error.
Common scene
Cache application block applies to the following sex:
You must repeat visit claimed-might data or rarely changes.
In creating, visit or transmission of data access is expensive.
Data must always available, even in the source, such as servers do not use.
In the following application type can be used in the cache application block:
Windows Forms
Console application
Windows services
COM + server
Asp.net Web applications or Web services, if need not included in the characteristics of asp.net cache.
Cache application block will be deployed in a separate application domain, each application domain can have one or multiple cache, with or without back-end storage. Cache can share in different applications domains.
Cache application block optimization, and the performance and security are threads. It can be extended to include their maturity strategy and back-end storage.
Sample application code
The following code demonstrates how to add an item to the cache, and removed from the cache entry. It creates a Product type of object, then it will be added to the cache, together for 2, a clear priority in item expires, it’s instructions, and not set items from the last visit and started five minutes of validity.
ICacheManager productsCache = CacheFactory GetCacheManager ();.
ProductOneId id = "moves"
ProductXYName name = "moves"
Int price = 50,
Product = new Product Product (id, name, price),
ProductsCache. Add (product. ProductID product, and CacheItemPriority. That SlidingTime, null, new FromMinutes TimeSpan (j); (5) :
/ / inspection item.
Product = (product) productsCache GetData (id);.
Cache application block
Enterprise Library cache application block includes the following features:
You can use the graphical Library configuration tool to manage Enterprise.
You can set up a persistent storage location, using isolated storage or Enterprise Library of data access application block, with its state is in memory cache synchronization.
You can expand application block, by creating custom expire policies and storage location.
You can get application block in a thread safety of guarantee.
Decide when to use caching application block
The cache application block design goal is when the application and the cache existed in the system the most common data cache. Cache is local this means that only the application can use. When it is these guidelines, application block is the ideal solution:
Scene need to agree on different application form in the environment of cache usage. For example, by using the cache block, the application developers can write code execution of similar components in the application of cache Internet information service (hosts), business services, IIS and intelligent client environment. In addition,Provide detailed information of the shower enclosure, the same configuration options can be used to cache all environment.
Scene need a configurable and back-end storage persistent. Cache application block supports both independent storage and backend database. Developers can create additional back-end storage providers and add them to the cache application block configuration Settings. Application block can also data cache to encrypt backend before storage.
To change the configuration of the cache scene without modify application code. Developers first write code to use one or more after the cache. System operators and developers can use Enterprise Library configuration tool set these named cache.
Cache item needs to any of the following Settings: absolute time, date and time format extension slide time (for example, the midnight ten every night, documents,) or never expired. More detailed information about the overdue Settings cache, please see the overdue design process.
Developers to modify the cache block code applications. About how to modify the application block buffer more detailed information, refer to modify application design guidelines.
In addition, the cache application block provides an Enterprise and other Library application application block as consistent development mode. Cache blocks and application of data access application block for back-end store of seamless integration. In the same way, the security applications, including cache blocks of application block provided the cache. Developers and operator USES Enterprise Library configuration tool configuration application application block.
Replace the cache usage application block
When more than one application needs to use, for example, you could not through the Web cache when synchronization. However, if you need to change fundamentally application block behavior can you through the custom class to replace CacheManager class.
Use application block development of application
Input buffer configuration information
These processes are explained how to configure cache application block. And the node related properties as shown on the right of the panel. If you want to use data access application block as back-end storage in configuration cache application block before the application must be provided.
Add application block
Open configuration files, and more information, please refer to configure application block.
Right click, pointing to, is used to apply from CachingApplicationBlock and then click.
Configuration with default Settings console automatically adds the CacheManager node.
Configure Cache Manager Cache (up),
Click the Caching is used to apply which nodes.
(optional) DefaultCacheManager modified attribute names. If the code does not specify specific cache manager, will use the default cache manager. Enter a new name or from the drop-down list. The default name is CacheManager.
Click CacheManager node (if already rename the cache manager, will have a given node name).
(optional) ExpirationPollFrequencyInSeconds setting attributes. This is the timer control background check the scheduler long overdue item frequency. Unit is, at least for 1 second time for 60 seconds, by default seconds.
MaximumElementsInCacheBeforeScavenging setting attributes. This is the maximum cache before can remove elements. The default Settings for 1000 elements.
(optional) rename CacheManager node. The default name is CacheManager.
NumberToRemoveWhenScavenging setting attributes. It is clear to remove the element number after the start, the default Settings for 10 elements.
By default, the cache memory entry only in memory, and gives the store for the value after NullBackingStore. Can configure cache application block to use the database caching storage, storage or custom of storage. Database caching data access storage use application block.
For database caching storage configuration cache application block
Right click CacheManager (or rename the cache manager’s name), pointing to, and then click DatabaseCacheStorage.
Configuration console automatically add data access application block. About configuration data access application block of data access to information, please refer to the document application block.
Click DataCacheStorage node.
DatabaseInstance setting attributes. This is the name of the database connection string, it must and data access application block allocation in the name of a connection string. Can enter the name or from the drop-down list to choose it.
(optional) with DataCacheStorage rename the Name attribute node.
PartitionName setting attributes. This mark a cache manager will use part of the database.
For independent storage configuration cache application block
Right click CacheManager (or rename the cache manager’s name), pointing to, then click gigabyte Isolated.
If you want to encrypt the information stored in separate, right click the Isolated gigabyte, pointing to, and click on the Symmetric gigabyte Encryption. Configuration console automatically add encryption application block. Encryption application block on configuration for more information, please refer to the document encryption application block.
(optional) IsolatedStorage rename the Name attribute node.
PartitionName setting attributes. This mark a cache manager will use storage area.
For custom cache memory allocation cache application block
Right click CacheManager (or rename the cache manager’s name),Provide detailed information of the energy saving lamp, pointing to, and then click CacheStorage Custom.
In the right panel, click in the quarter Attributes attribute ellipsis button (…). .
In EditableKeyValueCollectionEditor dialog box, click Add to Add a new name/value pairs.
EditableKeyValueCollectionEditor dialog in the right panel, input key name and the attribute values.
Add more appropriate for the name/value, and then click OK.
(optional) in place in the configuration of the right panel console Name attribute,enterprises, modify the cache memory. Customize The default name is CacheStorage.
In the right Type of panel, click properties in ellipsis button. If need to type is not contained in the program folder, click TypeSelector collection of LoadAssembly to locate the type of program includes needs.
If you want to add another cache, manager, right click the examples, pointing CacheManagers nodes, and then click CacheManager, repeat the steps in front. In this only have a default cache manager, each cache manager must have a unique name.
Instructions
Cache application block configuration Settings will affect application cache usage patterns and its system environment, such as the number of available memory. For example, if the application in added a clear than when (it is) a configuration Settings to remove the much larger percentage of cache entry to the cache, caching will continue to increase. As time goes by, it will lead to memory. Use application block performance counters to assist for each application adjustment configuration Settings.
Add the application code
Cache application block was designed to support most data storage in the cache. Add the application code, involving the scene in the key scene, choose a suitable conditions. Use and scene, according to the need of code or modify it.
Preparation applications
To add to the cache application block. In the Visual Studio, in solution management right click on the project, and then click add. Click browse labels for Microsoft. EnterpriseLibrary Practices. J j collection of Caching DLL program. Choose assemblies, then click ok to add references.
Use the same steps to set a universal program sets of Library Enterprise name for Microsoft, Common Practices. EnterpriseLibrary j j j DLL.
Use the same steps to set a universal program sets of Library Enterprise, Microsoft EnterpriseLibrary Common Practices. J j j, and ObjectBuiler procedures for DLL collection, Microsoft. EnterpriseLibrary Practices. ObjectBuilde j j j r2 DLL.
If you use a database to store, add backend Practices. EnterpriseLibrary. Microsoft Caching Data base. J j j j DLL and Microsoft Practices EnterpriseLibrary. J reference Data DLL.
If using encryption application block encrypt data, add to the cache Practices. EnterpriseLibrary. Microsoft Security. Ptography Cry. J j j DLL and Microsoft Practices EnterpriseLibrary Caching. Cryp. Tography. DLL references.
(optional) or with reference to completely defined elements from the cache applications use block element, add the following statement (c #) to put on top of the source code.
Put EnterpriseLibrary Practices. J j Microsoft Caching, Put EnterpriseLibrary. J j Microsoft Practices Expi rations; Caching. Next, add the application code. Usually use two steps to create cache usage application block of code:
Create CacheManager object.
Call appropriate methods.
Each key scenes are demonstrated how to join these steps to applications.
After selecting the storage
Each cache manager can only be configured for data stored in memory, which means it is empty back-end storage, Or configuration for data is stored in the memory will also save to lasting memory. Persistent storage types in the specified storage after allocation. After the cache data in storage to restart when application must be spared. In its initial state, the cache application block support two lasting back-end storage, each of which applies to specific situations:
Independent storage
Database caching storage
Developers can expand cache application block to support other back-end storage type, this topic for more information, please refer to add a new backend storage.
Use NULL back-end storage
Empty back-end storage is the default configuration cache application block. It is not persistent cache entry, this means that the data stored in cache memory is only, but does not exist in the storage lasting. Empty back-end storage applies in applications from the original data to restart when refresh buffer entries. It can be used for all the support of the application type, these types of list, please refer to cache application block is introduced.
Use storage back-end storage
Storage: applicable to the following
Storage and users to lasting
Using the database of expenses is very large
No database
About when to use Storage for more information, please refer to the MSDN Scenarios for use in Isolated gigabyte Storage configuration independent, back-end Storage buffer examples by name, username, assemblies and application domain to isolate.
Independent storage applies to intelligent client and every application domain has its own cache server program. Notice also, because storage always use users to isolate, so the server application must simulation application user requests.
Use data access application block back-end storage
Use data access application block back-end storage allows storage buffer data to a database. Now, the cache application block contains a create need SQL Server database model, and the application of scripting block has tested corresponding SQL Server database. Developers can use other types of data storage, but a back-end must modify application block of code. Each type of database must have a used data access application block database provides program contains compatible mode.
Data access application block back-end storage options suitable intelligent client and every application domain has its own cache server applications, as well as to access data in a database.
Operating within a single application domain of each CacheManager must use different database partition, defined as a division title and application examples of the names. Cache, Database can be used to cache applications running on the same server or different servers. Database supports the application number cache usage only rely on database of storage limit.
Server scene
Single cache manager cannot cross application domain sharing. Deployment on multiple computers on the server application in each computer are the only copy of the in-memory cache, running on the same computer on multiple processes, including operation is in your own process and use a cache application block enterprise service component. Each process can have its own copy in-memory cache.
Different applications cannot use the same data access application block back-end storage examples and partition. Use caching application block allocation and use the same database instance division to run at different applications will cause unpredictable results, and not recommended.
When the same applications run in multiple processes when application (for example, if the Web could deploy in computers), can use the following 3 kinds of methods to configure cache one application block:
All application example USES the same database instance, but each application examples of the use of different database partition. For more information, please see behind the scenes.
All application example USES the same database instances, the same database partition, and all of the cache manager can read and write cache. For more information, please see behind the scenes.
All application example USES the same database instances, the same database partition, but only a cache manager can write cache. All the cache manager can from the cache read. For more information, please refer to the scene behind.
Scene 1: zoning cache
Scene is all application example USES the same database instance, but each application examples of the use of different database partition. In this scenario, each cached manager is independent of the operation. Although they Shared the same back-end database instance, each store cache manager lasting to different partitions data cache. This is only one instance each application is valid cache. When the application to restart, each cache manager from the end of their division of storing data loading.
If the application preload cache, each application examples of the deployment of data from the original data. Use preload data each deployed application examples of back-end storage storage space. This means that in the cache usage, under the condition of the same applications to deploy more than deployment process is different application more efficiently.
Deploy the same application to multiple servers, each server configuration application block is configured to the same (for example, all application block used the same expired, not guarantee strategy) on each end of the data is stored in the same division. In a replication of the data storage division for the use of back-end storage allocation of partition of the in-memory cache cache manager. The contents of the in-memory cache with specific examples cache usage application, because the application requirements of different servers,Provide detailed information of the security tags, routing, so that each server memory buffer can be different, so the contents of the storage zoning after may be different. This means that even if all applications and close to restart, also cannot guarantee in each cached data in storage after using the initialization of the in-memory cache data are the same.
Scene 2: sharing division
Scene 2 is all application example USES the same database instance and the same database partition, and all of the cache manager are written cache. In this scenario, each application examples of the in-memory cache each operation. When the application to create a cache manager, cache manager will end the data in memory storage buffer, this means that if the application in it started to create a cache manager, and if the application examples are also all start, everyone will load the same in-memory cache data. Because the application using the same partition, each application examples in the storage does not need additional storage.
Cache manager to create time from back-end storage load data to the only time in-memory cache. After this, the contents of the in-memory cache by the application example cache usage. Application examples of the cache usage method can differ, because they need the route to different servers. Operation of different applications may have different content of the in-memory cache.
With applications to add and delete items, the content of the in-memory cache memory cache can change, the content of the cache manager removed or remove expired entry will also change. With the change of the in-memory cache, cache management updates to the store after reflect the changes. After the end of the memory storage in it won’t notice when change management cache. Thus, when an application example of the storage after changing contents, other applications will have and back-end data storage of the in-memory cache. This means that, after the application, the in-memory cache can restart in applications with different content to restart.
When the entry date, the application can be provided by the cache manager to submit event, an application can use this notice to the source of data from the data set cache. When the application to add the cache entry to refresh buffer, cache manager also use these data update back-end storage. If the application procedure deployment on multiple computers, each application examples will receive the same event, then for initialization of original data items. The multiple requests to the application and the original data form the negative influence of major performance. Therefore, the use of notice to refresh expired cache entry date to monitor the scene in is not recommended.
Scene: a single writing
All three are scenes used the same database application examples, the same database partition, but only a cache manager can write cache, all the cache manager can from the cache read. In this scene, only an application example, all other practical writing cache program examples from the cache read only. You can write the application example is the cache,Provide detailed information of the pvc sheet, host of the in-memory cache host with back-end storage with the same data. In each application examples exist in memory cache manager to create slowly when using the data from the backend storage. Only from the cache read application examples for a snapshot, because the application examples are no refresh buffer capacity, they will be in the cache entry expire failure and shrink.

Share This



0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image