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