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 * The nuxeo cache interface that define generic methods to use cache technologies 026 * 027 * @since 6.0 028 */ 029public interface Cache { 030 031 /** 032 * Get cache name as specified in the descriptor 033 * 034 * @return the cache name 035 * @since 6.0 036 */ 037 public String getName(); 038 039 /** 040 * Get method to retrieve value from cache Must not raise exception if the key is null, but return null 041 * 042 * @param key the string key 043 * @return the {@link Serializable} value, return null if the key does not exist or if the key is null 044 * @since 6.0 045 */ 046 public Serializable get(String key); 047 048 /** 049 * Invalidate the given key 050 * 051 * @param key, the key to remove from the cache, if null will do nothing 052 * @since 6.0 053 */ 054 public void invalidate(String key); 055 056 /** 057 * Invalidate all key-value stored in the cache 058 * 059 * @since 6.0 060 */ 061 public void invalidateAll(); 062 063 /** 064 * Put method to store a {@link Serializable} value 065 * 066 * @param key the string key, if null, the value will not be stored 067 * @param value the value to store, if null, the value will not be stored 068 * @since 6.0 069 */ 070 public void put(String key, Serializable value); 071 072 /** 073 * Check if a given key is present inside the cache. Compared to the get() method, this method must not update 074 * internal cache state and change TTL 075 * 076 * @param key the string key 077 * @return true if a corresponding entry exists, false otherwise 078 * @since 7.2 079 */ 080 public boolean hasEntry(String key); 081 082}