package com.gu.cache.simplecache;

import java.util.concurrent.TimeUnit;

public class KeyTranslatorSimpleCacheDecorator implements SimpleCache {

	private final SimpleCache delegate;
	private final KeyTranslator keyTranslator;

	public KeyTranslatorSimpleCacheDecorator(SimpleCache delegate, KeyTranslator keyTranslator) {
		this.delegate = delegate;
		this.keyTranslator = keyTranslator;
	}
	
	@Override
	public Object get(Object key) {
		Object translatedKey = keyTranslator.translate(key);
		return delegate.get(translatedKey);
	}

	@Override
	public CacheValueWithExpiryTime getWithExpiry(Object key) {
		Object translatedKey = keyTranslator.translate(key);
		return delegate.getWithExpiry(translatedKey);
	}

	@Override
	public void putWithExpiry(Object key, Object value, long lifetime,
			TimeUnit units) {
		Object translatedKey = keyTranslator.translate(key);
		delegate.putWithExpiry(translatedKey, value, lifetime, units);
	}

	@Override
	public void remove(Object key) {
		Object translatedKey = keyTranslator.translate(key);
		delegate.remove(translatedKey);
	}

	@Override
	public void removeAll() {
		delegate.removeAll();
	}

    @Override
    public boolean isServeStaleEnabled() {
        return delegate.isServeStaleEnabled();
    }

    @Override
    public void setServeStaleEnabled(boolean serveStaleEnabled) {
        delegate.setServeStaleEnabled(serveStaleEnabled);
    }
}
@@ -28,16 +28,49 @@
 cache;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 import j
@@ -99,16 +99,16 @@
 meUnit;%0A
-
 %0Apublic 
@@ -173,16 +173,111 @@
 ache %7B%0A%0A
+%09private static final Logger LOG = Logger.getLogger(KeyTranslatorSimpleCacheDecorator.class);%0A%0A
 %09private
@@ -552,32 +552,122 @@
 t(Object key) %7B%0A
+        if (LOG.isTraceEnabled()) %7B%0A            LOG.trace(%22get(%22 + key + %22)%22);%0A        %7D%0A%0A
 %09%09Object transla
@@ -811,32 +811,132 @@
 y(Object key) %7B%0A
+        if (LOG.isTraceEnabled()) %7B%0A            LOG.trace(%22getWithExpiry(%22 + key + %22)%22);%0A        %7D%0A%0A
 %09%09Object transla
@@ -1122,24 +1122,138 @@
 it units) %7B%0A
+    %09if (LOG.isTraceEnabled()) %7B%0A    %09%09LOG.trace(String.format(%22putWithExpiry(%25s) =%3E '%25s'%22, key, value));%0A    %09%7D%0A%0A
 %09%09Object tra
@@ -1367,32 +1367,32 @@
 %0A%09%7D%0A%0A%09@Override%0A
-
 %09public void rem
@@ -1409,16 +1409,121 @@
  key) %7B%0A
+        if (LOG.isTraceEnabled()) %7B%0A            LOG.trace(String.format(%22remove(%25s)%22, key) );%0A        %7D%0A%0A
 %09%09Object

Add untranslated key logging to KeyDecorator.