public void print(final Logger log) {
   final Collection<CacheLocation> locs = configuredLocations.values();
   for (CacheLocation loc : locs) {
     final String id = loc.getId();
     final List<Cache> caches = loc.getCaches();
     log.warn("CacheLocation: " + id);
     for (Cache c : caches) {
       log.warn("\tCache: " + c.getId() + " : " + c.toString());
     }
   }
 }
示例#2
0
  /**
   * Compile stats from all registered caches.
   *
   * <p>This is basically a hacky version of instrumentation which is being thrown in because we
   * don't have a full instrumentation strategy yet. This is here with the full expectation that it
   * will be replaced by something a bit more elaborate, like JMX.
   */
  public static Map getStats() {

    Map allStats = new HashMap();

    Cache cache = null;
    Iterator cachesIT = caches.values().iterator();
    while (cachesIT.hasNext()) {
      cache = (Cache) cachesIT.next();

      allStats.put(cache.getId(), cache.getStats());
    }

    return allStats;
  }
示例#3
0
  /**
   * Ask the CacheManager to construct a cache.
   *
   * <p>Normally the CacheManager will use whatever CacheFactory has been chosen for the system via
   * the cache.defaultFactory property. However, it is possible to override the use of the default
   * factory by supplying a "factory" property to this method. The value should be the full
   * classname for the factory you want to use for constructing the cache.
   *
   * <p>example: factory -> org.apache.roller.weblogger.util.cache.LRUCacheFactoryImpl
   *
   * <p>This allows Roller admins the ability to choose a caching strategy to use for the whole
   * system, but override it in certain places where they see fit. It also allows users to write
   * their own caching modifications and have them used only by specific caches.
   */
  public static Cache constructCache(CacheHandler handler, Map properties) {

    log.debug("Constructing new cache with props " + properties);
    Cache cache = null;

    if (properties != null && properties.containsKey("factory")) {
      // someone wants a custom cache instance
      String classname = (String) properties.get("factory");

      try {
        // use reflection to instantiate the factory class
        Class factoryClass = Class.forName(classname);
        log.info("PageCacheFactory:" + factoryClass);
        CacheFactory factory = (CacheFactory) factoryClass.newInstance();

        // now ask for a new cache
        cache = factory.constructCache(properties);
      } catch (ClassCastException cce) {
        log.error(
            "It appears that your factory ["
                + classname
                + "] does not implement the CacheFactory interface",
            cce);
      } catch (Exception e) {
        log.error(
            "Unable to instantiate cache factory [" + classname + "] falling back on default", e);
      }
    }

    if (cache == null) {
      // ask our default cache factory for a new cache instance
      cache = cacheFactory.constructCache(properties);
    }

    if (cache != null) {
      caches.put(cache.getId(), cache);

      // register the handler for this new cache
      if (handler != null) {
        cacheHandlers.add(handler);
      }
    }

    return cache;
  }