001package org.cache2k.integration;
002
003/*
004 * #%L
005 * cache2k API
006 * %%
007 * Copyright (C) 2000 - 2016 headissue GmbH, Munich
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import org.cache2k.Cache;
024
025import java.util.Map;
026import java.util.concurrent.Executor;
027
028/**
029 * Writer for write-through configurations. Any mutation of the cache via the
030 * {@link Cache}  interface, e.g.  {@link Cache#put(Object, Object)} or
031 * {@link Cache#remove(Object)}  will cause a writer call.
032 *
033 * @author Jens Wilke
034 */
035public abstract class CacheWriter<K, V> {
036
037  /**
038   * Called when the value was updated or inserted into the cache.
039   *
040   * <p><b>Calling cache operations:</b> It is illegal to call any
041   * cache methods from this method. This may have an undesired effect
042   * and can cause a deadlock.
043   *
044   * @param key key of the value to be written, never null.
045   * @param value the value to be written, may be null if null is permitted.
046   * @throws Exception if an exception occurs, the cache update will not occur and this
047   *         exception will be wrapped in a {@link CacheWriterException}
048   */
049  public abstract void write(K key, V value) throws Exception;
050
051  /**
052   * Called when a mapping is removed from the cache. The removal was done by
053   * {@link Cache#remove} or {@link Cache#removeAll()}. An expiry does not trigger a call
054   * to this method.
055   *
056   * @param key key of the value removed from the cache, never null.
057   * @throws Exception if an exception occurs, the cache update will not occur and this
058   *         exception will be wrapped in a {@link CacheWriterException}
059   */
060  public abstract void delete(K key) throws Exception;
061
062
063}