org.apache.shindig.gadgets.http
Class CacheKeyBuilder

java.lang.Object
  extended by org.apache.shindig.gadgets.http.CacheKeyBuilder

public class CacheKeyBuilder
extends Object

Builds the cache key object.

Takes extra care to build the cache keys that don't thrash persistent caches.


Constructor Summary
CacheKeyBuilder()
           
 
Method Summary
 String build()
          Inserting the keys from the parameter map only if the keys are defined, prevents thrashing the existing persistent caches at rolling restart of high-traffic servers.
 CacheKeyBuilder setLegacyParam(int index, Object value)
          Sets a legacy cache key parameter.
 CacheKeyBuilder setParam(String name, Object value)
          Sets a cache key parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheKeyBuilder

public CacheKeyBuilder()
Method Detail

setLegacyParam

public CacheKeyBuilder setLegacyParam(int index,
                                      Object value)
Sets a legacy cache key parameter.

The legacy cache key parameters have a fixed order. Since the cache key is not required to have all of the legacy parameters filled in, the index of the parameter must be given.

Parameters:
index - the index to place this parameter at; valid values are 0 to - 1
value - the object that determines the legacy parameter

setParam

public CacheKeyBuilder setParam(String name,
                                Object value)
Sets a cache key parameter.

Each parameter needs to be inserted in the cache key builder manually, so that the user has an option to select the parameters that need to become part of the key.

Parameters:
name - the parameter name; if null, the param will not be inserted
value - the object that determines the value of the parameter

build

public String build()
Inserting the keys from the parameter map only if the keys are defined, prevents thrashing the existing persistent caches at rolling restart of high-traffic servers. The cache keys of all URIs that don't set these parameters must not change. TODO: String parameters that have KEY_SEPARATOR appearing as a part of a string param need to be escaped (e.g. with a backslash like so: ":" -> "\:") to prevent weird cache key collisions. Moreover the active character (backslash) needs to be escaped itself for similar reasons.



Copyright © 2007-2012. All Rights Reserved.