View Javadoc
1   package com.atlassian.cache.ehcache.wrapper;
2   
3   import com.atlassian.cache.CacheLoader;
4   import net.sf.ehcache.CacheException;
5   
6   import javax.annotation.Nonnull;
7   
8   /**
9    * Decorates the loader of {@link com.atlassian.cache.ehcache.LoadingCache}.
10   * We make sure that during the loading operation, wrapped key does not leak to the end user.
11   */
12  public class ValueProcessorAtlassianCacheLoaderDecorator implements CacheLoader<Object, Object> {
13  
14      private final CacheLoader delegate;
15      private final ValueProcessor valueProcessor;
16  
17      public ValueProcessorAtlassianCacheLoaderDecorator(final CacheLoader delegate, final ValueProcessor valueProcessor) {
18          this.delegate = delegate;
19          this.valueProcessor = valueProcessor;
20      }
21  
22      @SuppressWarnings("unchecked")
23      @Override
24      @Nonnull
25      public Object load(@Nonnull final Object key) throws CacheException {
26          return valueProcessor.wrap(delegate.load(valueProcessor.unwrap(key)));
27      }
28  }