fcSDK Documentation Send comments on this topic.

Configuring fcSDK

Configuring Custom Cache Providers


Configuring CacheManager to load a custom cache object

CacheManager looks in the .NET configuration file for a specific configuration section called "customCaches". You must define this section at the top (it must be at the top) of the configuration file in the "configSections" element.

For example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="customCaches" type="FChoice.Foundation.CacheSectionHandler, FChoice.Foundation"/>
    </configSections>    
    
    ... (rest of config file) ...
</configuration>
		

Once you have defined the "customCaches" section, you can specify any number of custom caches using the "customCache" element.

For example:

    ... (start of config file referenced above) ...
    
    <customCaches>
        <customCache
            name="myCustomCache"
            type="MyNamespace.ClassName, MyAssemblyName"
            parameters="any optional initialization parameters here"  />
        <customCache
            name="anotherCustomCache"
            type="MyNamespace.AnotherClassName, MyAssemblyName"
            parameters="1, 2, 3, 4"  />
    </customCaches>
    
    ... (rest of config file) ...
    
</configuration>

customCache Element Schema

This table describes the attributes required for the customCache element.
Attribute Required Description
name Yes A key used by CacheManager to distinguish this cache. The instance of the cache created and loaded by CacheManager can be retrieved using this key with the CacheManager.GetCache method.
NOTE: CacheManager will load hard-coded caches such as the ListCache and LocaleCache before loading custom caches. These caches have specific names. If you specify a custom cache name that conflicts with one of these hard-coded cache names, an error will be thrown. These names are:
  • configitem_cache
  • list_cache
  • locale_cache
  • schema_cache
  • string_cache
type Yes The fully qualified type name of a class which derrives from FChoice.Foundation.CacheBase.
NOTE: Please refer to the Type.GetType method documentation for information for the specific format of the value of this attribute.
parameters (see description) Specifies any initialization parameters to pass to the custom cache object during initialization. Whether or not this attribute is required depends on the specific implementation of the custom cache object. For example, the CustomCache object which ships with the fcSDK requires this parameter to be a comma-delimited list of tables in the database to cache in memory and on disk.

Simple table caching using the CustomCache object

The fcSDK includes a simple "CustomCache" object which can cache one or more tables into a dataset. It executes a simple "SELECT * FROM" sql query for each of the table you specify. This is useful if you want to cache a small table or tables of static values.

In your config file, include the customCaches config section as mentioned above and define a custom cache with whatever name you wish to assign it. For the type attribute, use "FChoice.Foundation.CustomCache, FChoice.Foundation". The parameters attribute must contain at least one table name (the full SQL table name including the table_ prefix). Multiple tables can be specified separated by a comma.

For Example, if you wanted to cache the fc_string table (even though it's already cached):

    ... (start of config file referenced above) ...
    
    <customCaches>
        <customCache
            name="fcStringCache"
            type="FChoice.Foundation.CustomCache, FChoice.Foundation"
            parameters="table_fc_string"  />
    </customCaches>
    
    ... (rest of config file) ...
    
</configuration>

Creating your own custom cache object


In order to have CacheManager load your custom cache object, you must derrive from FChoice.Foundation.CacheBase. At the very least, you must override the "InitCacheData" method.

Cache load lifecycle

During Initialization:

During Cache Update (UpdateCache called)
NOTE: ReadCacheData and PersistCacheData are not called if the "nocachefile" configuration value is set to "true". Please consult the basic configuration guide for more details on this value.

InitCacheData

This method will be called when CacheManager cannot find any existing persisted cache data (on disk) for your object. The implementation of this method is expected to perform whatever steps are necessary to produce a data object. This object will be returned back to CacheManager which will then save it to disk. The default implementation expects this object to be a System.Data.DataSet object. CacheManager has a specific optimized binary serializer for DataSets. Generally, the implementation of this method will make a SQL query to a database and return a DataSet.

Optionally, you can override the LoadCacheData method

This method will be called after the cache data has been loaded from the data source or read from the cache persistance (usually files on the disk). In this method is where you might create strongly-typed objects based on the data such as what the various fcSDK caches do with their objects (such as with the LocaleCache and the Country, FCTimeZone, and StateProvince objects).

It is not a requirement that this method do anything at all

Using a custom data object type (other than DataSet)

If you plan on working with a cache object of a type other than DataSet, you MUST override the PersistCacheData and ReadCacheData methods to handle the custom serialization of the data.