/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.cache.internal;

import java.util.HashMap;
import java.util.Map;

import org.xwiki.cache.Cache;
import org.xwiki.cache.util.AbstractCache;

/**
 * Implementation of {@link Cache} based on a simple Map.
 * <p>
 * Does not support eviction.
 * 
 * @param <T> the class of the data stored in the cache.
 * @version $Id$
 */
public class MapCache<T> extends AbstractCache<T>
{
    private Map<String, T> map = new HashMap<>();

    /**
     * Default constructor.
     */
    public MapCache()
    {
        super(null);
    }

    @Override
    public void set(String key, T value)
    {
        this.map.put(key, value);
    }

    @Override
    public T get(String key)
    {
        return this.map.get(key);
    }

    @Override
    public void remove(String key)
    {
        this.map.remove(key);
    }

    @Override
    public void removeAll()
    {
        this.map.clear();
    }
}

@@ -1001,16 +1001,97 @@
 .Cache;%0A
+import org.xwiki.cache.CacheEntry;%0Aimport org.xwiki.cache.event.CacheEntryEvent;%0A
 import o
@@ -1418,95 +1418,1074 @@
     
-/**%0A     * Default constructor.%0A     */%0A    public MapCache()%0A    %7B%0A        super(null)
+class MapCacheEntry implements CacheEntry%3CT%3E%0A    %7B%0A        private final String key;%0A%0A        private final T value;%0A%0A        MapCacheEntry(String key, T value)%0A        %7B%0A            this.key = key;%0A            this.value = value;%0A        %7D%0A%0A        @Override%0A        public Cache%3CT%3E getCache()%0A        %7B%0A            return MapCache.this;%0A        %7D%0A%0A        @Override%0A        public String getKey()%0A        %7B%0A            return this.key;%0A        %7D%0A%0A        @Override%0A        public T getValue()%0A        %7B%0A            return this.value;%0A        %7D%0A    %7D%0A%0A    /**%0A     * Default constructor.%0A     */%0A    public MapCache()%0A    %7B%0A        super(null);%0A    %7D%0A%0A    private CacheEntryEvent%3CT%3E toEvent(final String key, final T value)%0A    %7B%0A        return new CacheEntryEvent%3CT%3E()%0A        %7B%0A            @Override%0A            public CacheEntry%3CT%3E getEntry()%0A            %7B%0A                return new MapCacheEntry(key, value);%0A            %7D%0A%0A            @Override%0A            public Cache%3CT%3E getCache()%0A            %7B%0A                return MapCache.this;%0A            %7D%0A        %7D
 ;%0A  
@@ -2579,24 +2579,75 @@
 key, value);
+%0A%0A        sendEntryAddedEvent(toEvent(key, value));
 %0A    %7D%0A%0A    
@@ -2799,107 +2799,586 @@
     
-this.map.remove(key);%0A    %7D%0A%0A    @Override%0A    public void removeAll()%0A    %7B%0A        this.map.clear
+if (this.map.containsKey(key)) %7B%0A            T value = this.map.remove(key);%0A%0A            sendEntryRemovedEvent(toEvent(key, value));%0A        %7D else %7B%0A            this.map.remove(key);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void removeAll()%0A    %7B%0A        this.map.clear();%0A%0A        Map%3CString, T%3E eventMap = new HashMap%3C%3E(this.map);%0A%0A        for (Map.Entry%3CString, T%3E entry : eventMap.entrySet()) %7B%0A            sendEntryRemovedEvent(toEvent(entry.getKey(), entry.getValue()));%0A        %7D%0A    %7D%0A%0A    @Override%0A    public String toString()%0A    %7B%0A        return this.map.toString
 ();%0A

Add support for listener in MapCache