Share via


Adding a New Cache

You can create a cache using either a dictionary or LRUCache object. The choice depends on how you use the cache. If you are going to cache HTML fragments, particularly if the number of fragments is likely to grow beyond a reasonable cache size, it is advisable that you use the LRUCache object. The wrapper functions discussed in Catalog Caching for Solution Sites expect an LRUCache object.

Initialize your cache in the file include\std_cache_lib.asp. Depending on how you want to refresh your cache, you may need to modify the file BDRefresh.asp as follows. If you are adding another catalog cache you will need to add it to the list catalog caches. If you are adding multiple caches that must be refreshed together, you will need to add a an additional case statement to detect your cache names and refresh all of your caches

In order to refresh a cache from Commerce Server Business Desk the CacheLoader component has to notify Business Desk that the cache is present. The CacheLoader component inserts a new record, or updates an existing record, in a table in your site database with the computer URL, the cache name, and the date created. If you are adding an additional catalog-related cache you can use the same table as the other catalog caches, the CatalogCache_Virtual_Directory table.

If you are adding a cache for data that is not related to an existing data source you will want to create a new table for registering the cache. See the txVirtual_directory table, used for order related caches, in the Solution Sites database for an example of the table to create if you are caching data from a different source. You will need to modify Business Desk to look at your new table. See the retailbizdesk\productionrefresh\refresh.asp file in the Business Desk site for an example of Business Desk code that triggers a cache refresh.

The LRUCacheLoader component uses information in the LoaderConfig dictionary to write the necessary record the first time the cache is called. The following code shows how the cache ProductListCache is configured:

'Get the connection string from the configuration dictionary.
'This is the connection string to the database containing the table.
    dictProductListCacheConfig("ConnectionString") = _
       dictConfig.s_TransactionConfigConnectionString

'Set the name of the table used to provide information to Business Desk.
    dictProductListCacheConfig("TableName") = _
        "CatalogCache_Virtual_Directory"

'CacheName is one of the fields inserted in the above table.
'It also is used in BDRefresh.asp to trigger 
'refreshing all catalog caches.
    dictProductListCacheConfig("CacheName") = "CatalogCache"
'Machine Base URL, to be inserted in the above table.
    dictProductListCacheConfig("AppUrl") = sMachineBaseURL
...

See Also

Code to Implement Custom Cache Components

Code to Manipulate an LRUCache Object

Building Pipeline Components

Building Business Desk Modules

Copyright © 2005 Microsoft Corporation.
All rights reserved.