Search in sources :

Example 1 with Revisioned

use of org.keycloak.models.cache.infinispan.entities.Revisioned in project keycloak by keycloak.

the class InfinispanCacheStoreFactoryProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (storeCache == null) {
        synchronized (this) {
            if (storeCache == null) {
                Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.AUTHORIZATION_CACHE_NAME);
                Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.AUTHORIZATION_REVISIONS_CACHE_NAME);
                storeCache = new StoreFactoryCacheManager(cache, revisions);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(AUTHORIZATION_INVALIDATION_EVENTS, (ClusterEvent event) -> {
                    InvalidationEvent invalidationEvent = (InvalidationEvent) event;
                    storeCache.invalidationEventReceived(invalidationEvent);
                });
                cluster.registerListener(AUTHORIZATION_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> storeCache.clear());
                cluster.registerListener(REALM_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> storeCache.clear());
                log.debug("Registered cluster listeners");
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned) ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent)

Example 2 with Revisioned

use of org.keycloak.models.cache.infinispan.entities.Revisioned in project keycloak by keycloak.

the class InfinispanUserCacheProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (userCache == null) {
        synchronized (this) {
            if (userCache == null) {
                Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_CACHE_NAME);
                Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.USER_REVISIONS_CACHE_NAME);
                userCache = new UserCacheManager(cache, revisions);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(USER_INVALIDATION_EVENTS, (ClusterEvent event) -> {
                    InvalidationEvent invalidationEvent = (InvalidationEvent) event;
                    userCache.invalidationEventReceived(invalidationEvent);
                });
                cluster.registerListener(USER_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
                    userCache.clear();
                });
                log.debug("Registered cluster listeners");
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned) ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent)

Example 3 with Revisioned

use of org.keycloak.models.cache.infinispan.entities.Revisioned in project keycloak by keycloak.

the class CacheManager method get.

public <T extends Revisioned> T get(String id, Class<T> type) {
    Revisioned o = (Revisioned) cache.get(id);
    if (o == null) {
        return null;
    }
    Long rev = revisions.get(id);
    if (rev == null) {
        if (getLogger().isTraceEnabled()) {
            getLogger().tracev("get() missing rev {0}", id);
        }
        /* id is no longer in this.revisions
             ** => remove it also from this.cache
             ** to come back to a consistent state
             ** this allows caching the current version again
             */
        cache.remove(id);
        return null;
    }
    long oRev = o.getRevision() == null ? -1L : o.getRevision().longValue();
    if (rev > oRev) {
        if (getLogger().isTraceEnabled()) {
            getLogger().tracev("get() rev: {0} o.rev: {1}", rev.longValue(), oRev);
        }
        // the object in this.cache is outdated => remove it
        cache.remove(id);
        return null;
    }
    return o != null && type.isInstance(o) ? type.cast(o) : null;
}
Also used : Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned)

Example 4 with Revisioned

use of org.keycloak.models.cache.infinispan.entities.Revisioned in project keycloak by keycloak.

the class CacheManager method invalidateObject.

public Object invalidateObject(String id) {
    Revisioned removed = (Revisioned) cache.remove(id);
    if (getLogger().isTraceEnabled()) {
        getLogger().tracef("Removed key='%s', value='%s' from cache", id, removed);
    }
    bumpVersion(id);
    return removed;
}
Also used : Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned)

Example 5 with Revisioned

use of org.keycloak.models.cache.infinispan.entities.Revisioned in project keycloak by keycloak.

the class InfinispanCacheRealmProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (realmCache == null) {
        synchronized (this) {
            if (realmCache == null) {
                Cache<String, Revisioned> cache = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_CACHE_NAME);
                Cache<String, Long> revisions = session.getProvider(InfinispanConnectionProvider.class).getCache(InfinispanConnectionProvider.REALM_REVISIONS_CACHE_NAME);
                realmCache = new RealmCacheManager(cache, revisions);
                ClusterProvider cluster = session.getProvider(ClusterProvider.class);
                cluster.registerListener(REALM_INVALIDATION_EVENTS, (ClusterEvent event) -> {
                    InvalidationEvent invalidationEvent = (InvalidationEvent) event;
                    realmCache.invalidationEventReceived(invalidationEvent);
                });
                cluster.registerListener(REALM_CLEAR_CACHE_EVENTS, (ClusterEvent event) -> {
                    realmCache.clear();
                });
                log.debug("Registered cluster listeners");
            }
        }
    }
}
Also used : ClusterEvent(org.keycloak.cluster.ClusterEvent) Revisioned(org.keycloak.models.cache.infinispan.entities.Revisioned) ClusterProvider(org.keycloak.cluster.ClusterProvider) InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent)

Aggregations

Revisioned (org.keycloak.models.cache.infinispan.entities.Revisioned)5 ClusterEvent (org.keycloak.cluster.ClusterEvent)3 ClusterProvider (org.keycloak.cluster.ClusterProvider)3 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)3 InvalidationEvent (org.keycloak.models.cache.infinispan.events.InvalidationEvent)3