001/*
002 * (C) Copyright 2014 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Maxime Hilaire
016 *
017 */
018package org.nuxeo.ecm.core.cache;
019
020import java.io.IOException;
021import java.io.Serializable;
022
023/**
024 * The nuxeo cache interface that define generic methods to use cache technologies
025 *
026 * @since 6.0
027 */
028public interface Cache {
029
030    /**
031     * Get cache name as specified in the descriptor
032     *
033     * @return the cache name
034     * @since 6.0
035     */
036    public String getName();
037
038    /**
039     * Get method to retrieve value from cache Must not raise exception if the key is null, but return null
040     *
041     * @param key the string key
042     * @return the {@link Serializable} value, return null if the key does not exist or if the key is null
043     * @since 6.0
044     */
045    public Serializable get(String key);
046
047    /**
048     * Invalidate the given key
049     *
050     * @param key, the key to remove from the cache, if null will do nothing
051     * @since 6.0
052     */
053    public void invalidate(String key);
054
055    /**
056     * Invalidate all key-value stored in the cache
057     *
058     * @since 6.0
059     */
060    public void invalidateAll();
061
062    /**
063     * Put method to store a {@link Serializable} value
064     *
065     * @param key the string key, if null, the value will not be stored
066     * @param value the value to store, if null, the value will not be stored
067     * @since 6.0
068     */
069    public void put(String key, Serializable value);
070
071    /**
072     * Check if a given key is present inside the cache. Compared to the get() method, this method must not update
073     * internal cache state and change TTL
074     *
075     * @param key the string key
076     * @return true if a corresponding entry exists, false otherwise
077     * @since 7.2
078     */
079    public boolean hasEntry(String key);
080
081}