SynchronizedCache.java

  1. /*
  2.  *    Copyright 2009-2021 the original author or authors.
  3.  *
  4.  *    Licensed under the Apache License, Version 2.0 (the "License");
  5.  *    you may not use this file except in compliance with the License.
  6.  *    You may obtain a copy of the License at
  7.  *
  8.  *       http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *    Unless required by applicable law or agreed to in writing, software
  11.  *    distributed under the License is distributed on an "AS IS" BASIS,
  12.  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *    See the License for the specific language governing permissions and
  14.  *    limitations under the License.
  15.  */
  16. package org.apache.ibatis.cache.decorators;

  17. import org.apache.ibatis.cache.Cache;

  18. /**
  19.  * @author Clinton Begin
  20.  */
  21. public class SynchronizedCache implements Cache {

  22.   private final Cache delegate;

  23.   public SynchronizedCache(Cache delegate) {
  24.     this.delegate = delegate;
  25.   }

  26.   @Override
  27.   public String getId() {
  28.     return delegate.getId();
  29.   }

  30.   @Override
  31.   public synchronized int getSize() {
  32.     return delegate.getSize();
  33.   }

  34.   @Override
  35.   public synchronized void putObject(Object key, Object object) {
  36.     delegate.putObject(key, object);
  37.   }

  38.   @Override
  39.   public synchronized Object getObject(Object key) {
  40.     return delegate.getObject(key);
  41.   }

  42.   @Override
  43.   public synchronized Object removeObject(Object key) {
  44.     return delegate.removeObject(key);
  45.   }

  46.   @Override
  47.   public synchronized void clear() {
  48.     delegate.clear();
  49.   }

  50.   @Override
  51.   public int hashCode() {
  52.     return delegate.hashCode();
  53.   }

  54.   @Override
  55.   public boolean equals(Object obj) {
  56.     return delegate.equals(obj);
  57.   }

  58. }