Cache Extensions

This little module provides information about extensions of the Content Delivery caching mechanism.

Cache Channel Service with Debug Logging

Running CCS in debug mode will write all logging output by CCS to a file.

Specify the file to log to as part of the cd_tdf_conf.xml. The TDFramework uses the Tridion Content Delivery logging framework, so your cd_tdf_conf.xml could look like:

<configuration>
        <Logging>
                <Logger Level="debug">
                        <FileLogger Location="ccs.log" MaximumFileSize="50K" NumberOfFiles="2"/>
                        <ConsoleLogger Trace="false"/>
                </Logger>
        </Logging>
</configuration>

Startup the CCS in debug mode from a batch (or shell) file:

set classpath=config;lib\cd_broker.jar;lib\cd_core.jar;lib\cacheextension-1.1.jar;lib\tdframework-1.3.13.jar; 
java -cp "%CLASSPATH%" com.tridion.extension.ccs.CacheChannelDebugger 127.0.0.1:7777

, where config is a folder containing the cd_tdf_conf.xml.

More information about using the CCS on different ports can be found on Specific_RMI_Ports.

Also as of T2009, the port of the Broker, Deployer, Linker can be specified in their respective cd_*_conf.xml files.

Counting Cache Decorator

Few people know that the default Broker Cache provides a cache decorating mechanism. This proves to be especially usefull when you want to embellish (well... decorate) the caching behaviour.

The Cache Extensions module contains a cache decorator that keeps counts of cache reads, writes and removes. This is implemented in class com.tridion.cache.CountingCacheDecorator.

For writing such a Cache Decorator one would need to extend class com.tridion.cache.CacheProcessorDecorator. As an mild annoyance, your CacheDecorator class has be defined in package com.tridion.cache. This is due to the limited visibility of interface com.tridion.cache.CacheProcessor, which CacheProcessorDecorator implements.

The code is straight forward, basically simply wrapping (decorating) the existing cache process* methods:

/**
 * Increment the number of reads from global and region caches.
 * 
 * @see com.tridion.cache.CacheProcessorDecorator#processGet(com.tridion.cache.CacheElement)
 */
public void processGet(CacheElement element) throws CacheException {
        super.processGet(element);
        //do your own decorating here such as cacheCounter.incrementReads(region);
} 
/**
 * Increment the number of writes from global and region caches.
 * 
 * @see com.tridion.cache.CacheProcessorDecorator#processPut(com.tridion.cache.CacheElement)
 */
public void processPut(CacheElement element) throws CacheException {
        super.processPut(element);
        cacheCounter.incrementWrites(region);
} 
/**
 * Increment the number of deletes from global and region caches.
 * 
 * @see com.tridion.cache.CacheProcessorDecorator#processRemove(com.tridion.cache.CacheElement, boolean)
 */
public boolean processRemove(CacheElement element, boolean force) throws CacheException {
        cacheCounter.incrementDeletes(region);
        return super.processRemove(element, force);
} 
/**
 * Reset the counters in the global and region caches.
 * 
 * @see com.tridion.cache.CacheProcessorDecorator#processFlush()
 */
public void processFlush() throws CacheException {
        super.processFlush();
        cacheCounter.reset();
}

To enable your decorator, simply add it to the Features node in your cd_broker_conf.xml. In the case of the CountingCacheDecorator, the config looks like this:

<ObjectCache Enabled="true">
        <Policy Type="LRU" Class="com.tridion.cache.LRUPolicy">
                <Param Name="MemSize" Value="16mb"/>
        </Policy> 
        <Features>
                <Feature Type="DependencyTracker" Class="com.tridion.cache.DependencyTracker"/>
                <Feature Type="WhateverTypeHere" Class="com.tridion.cache.CountingCacheDecorator"/>
        </Features>
...

This class outputs statistics of the reads, write, removes from each Cache region into the broker log:

[Debug 22-01-2010 12:05:25] CacheCounter [Reads:9 Writes:15 Deletes:1]
        RegionCounter /com.tridion.ComponentPresentation [R:2 W:2 D:0]
        RegionCounter /com.tridion.broker.componentpresentations.meta.ComponentPresentationMeta [R:4 W:2 D:0]
        RegionCounter /com.tridion.broker.components.meta.ComponentMeta [R:0 W:2 D:0]
        RegionCounter /com.tridion.broker.pages.meta.PageMeta [R:2 W:3 D:1]
        RegionCounter /com.tridion.profserv.CWA [R:0 W:1 D:0]
        RegionCounter /com_tridion_linking_ComponentLinkInfo [R:0 W:3 D:0]
        RegionCounter /com_tridion_linking_PageLinkInfo [R:1 W:2 D:0]

About the Author
Mihai Cadariu
Senior Consultant

Mihai Cadariu is a Senior Technical Consultant and has been working for SDL Tridion since 2005. He is a Certified Consultant with strong web development skills; therefore he specialized in Content Delivery.

SDL CMT division