001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Maxime Hilaire 018 * 019 */ 020package org.nuxeo.ecm.core.cache; 021 022import java.io.Serializable; 023 024/** 025 * Class to implement mandatory check attributes before calling implementation of cache This enable to have the same 026 * behavior for any use of cache for all implementation of cache 027 * 028 * @since 6.0 029 */ 030public class CacheAttributesChecker extends AbstractCache { 031 032 protected Cache cache; 033 034 protected CacheAttributesChecker(CacheDescriptor desc) { 035 super(desc); 036 } 037 038 void setCache(Cache cache) { 039 this.cache = cache; 040 } 041 042 public Cache getCache() { 043 return cache; 044 } 045 046 @Override 047 public Serializable get(String key) { 048 if (key == null) { 049 return null; 050 } 051 return cache.get(key); 052 } 053 054 @Override 055 public void invalidate(String key) { 056 if (key == null) { 057 throw new IllegalArgumentException(String.format("Can't invalidate a null key for the cache '%s'!", name)); 058 } 059 cache.invalidate(key); 060 } 061 062 @Override 063 public void invalidateAll() { 064 cache.invalidateAll(); 065 } 066 067 @Override 068 public void put(String key, Serializable value) { 069 if (key == null) { 070 throw new IllegalArgumentException(String.format("Can't put a null key for the cache '%s'!", name)); 071 } 072 cache.put(key, value); 073 } 074 075 @Override 076 public boolean hasEntry(String key) { 077 if (key == null) { 078 return false; 079 } 080 return cache.hasEntry(key); 081 } 082 083}