Remove map listener when caching async consistent map is destroyed

Change-Id: I924609fa484d469c6ea290e9c8879d1ab49cf9fa
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CachingAsyncConsistentMap.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CachingAsyncConsistentMap.java
index aaa01e4..5054a0d 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CachingAsyncConsistentMap.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CachingAsyncConsistentMap.java
@@ -21,6 +21,7 @@
 import java.util.function.Predicate;
 
 import org.onosproject.store.service.AsyncConsistentMap;
+import org.onosproject.store.service.MapEventListener;
 import org.onosproject.store.service.Versioned;
 
 import com.google.common.cache.CacheBuilder;
@@ -51,9 +52,16 @@
                             }
                         });
 
+    private final MapEventListener<K, V> cacheInvalidator = event -> cache.invalidate(event.key());
+
     public CachingAsyncConsistentMap(AsyncConsistentMap<K, V> backingMap) {
         super(backingMap);
-        super.addListener(event -> cache.invalidate(event.key()));
+        super.addListener(cacheInvalidator);
+    }
+
+    @Override
+    public CompletableFuture<Void> destroy() {
+        return super.destroy().thenCompose(v -> removeListener(cacheInvalidator));
     }
 
     @Override