1 Reply Latest reply on Sep 5, 2013 10:13 AM by alexey.ragozin

    Custom Eviction policy to extend HYBRID policy




      I have implemented data affinity between 3 distributed caches under one(obviously) distributed service. If I configure out-of-box(LRU, LFU, HYBRID) eviction policy, it will evict selected entries only from one cache but NOT its key-associated entries from the other 2 caches, leaving the cluster/data-affinity in inconsistent state.


      So, I was wondering if its possible for a custom eviction policy to extend the HYBRID(out-of-box) behaviour, do an additional check on the entry and then evict the entry and its key-associated entries from other 2 caches. If possible would like coherence to indentify the entries to evict based on HYBRID policy rather than custom policy scanning the entrie cache and identify the potential entries to evict, then custom eviction policy will do an additional check on the entry and evict it and its key-associated entries from  other 2 caches.


      Would really appreciate any ideas/help on how this can be acheived.




        • 1. Re: Custom Eviction policy to extend HYBRID policy



          It is impossible to subclass default HYBRID policy.

          It is possible to subclass LocalCache and override evict(Object) / evictAll(Collection) methods to add additional check, though.

          In later case your custom map should be used as backing map for cache.


          You can clean up associated entries from other backing maps from overridden evict(...) methods too.


          You can use static factory to configure custom backing maps between associated cache i.e:


          class AssociatedBackingMapFactory {
               public static LocalCache getMainBM(String cacheName) {
                    return ensureGroup(getCacheGroupName(cacheName).main;
               public static LocalCache getAssociatedBM1(String cacheName) {
                    return ensureGroup(getCacheGroupName(cacheName).associated1;
               public static LocalCache getAssociatedBM2(String cacheName) {
                    return ensureGroup(getCacheGroupName(cacheName).associated2;
              private String getCacheGroupName(String cacheName) { ... }
              private BackingMapGroup ensureGroup(String groupName) { ... }
              private static class BackingMapGroup {
                  LocalCache main;
                  LocalCache associated1;
                  LocalCache associated2;