@Override public ClientModel getClientById(String id, RealmModel realm) { if (!cache.isEnabled()) return getDelegate().getClientById(id, realm); CachedClient cached = cache.getApplication(id); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { ClientModel model = getDelegate().getClientById(id, realm); if (model == null) return null; if (appInvalidations.contains(id)) return model; cached = new CachedClient(cache, getDelegate(), realm, model); cache.addCachedClient(cached); } else if (appInvalidations.contains(id)) { return getDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientAdapter adapter = new ClientAdapter(realm, cached, this, cache); managedApplications.put(id, adapter); return adapter; } @Override
protected ClientModel cacheClient(RealmModel realm, ClientModel delegate, Long revision) { if (invalidations.contains(delegate.getId())) return delegate; StorageId storageId = new StorageId(delegate.getId()); CachedClient cached = null; ClientAdapter adapter = null; if (!storageId.isLocal()) { ComponentModel component = realm.getComponent(storageId.getProviderId()); ClientStorageProviderModel model = new ClientStorageProviderModel(component); if (!model.isEnabled()) { return delegate; } ClientStorageProviderModel.CachePolicy policy = model.getCachePolicy(); if (policy != null && policy == ClientStorageProviderModel.CachePolicy.NO_CACHE) { return delegate; } cached = new CachedClient(revision, realm, delegate); adapter = new ClientAdapter(realm, cached, this); long lifespan = model.getLifespan(); if (lifespan > 0) { cache.addRevisioned(cached, startupRevision, lifespan); } else { cache.addRevisioned(cached, startupRevision); } } else { cached = new CachedClient(revision, realm, delegate); adapter = new ClientAdapter(realm, cached, this); cache.addRevisioned(cached, startupRevision); } return adapter; }
protected ClientModel validateCache(RealmModel realm, CachedClient cached) { if (!realm.getId().equals(cached.getRealm())) { return null; } StorageId storageId = new StorageId(cached.getId()); if (!storageId.isLocal()) { ComponentModel component = realm.getComponent(storageId.getProviderId()); ClientStorageProviderModel model = new ClientStorageProviderModel(component); // although we do set a timeout, Infinispan has no guarantees when the user will be evicted // its also hard to test stuff if (model.shouldInvalidate(cached)) { registerClientInvalidation(cached.getId(), cached.getClientId(), realm.getId()); return getClientDelegate().getClientById(cached.getId(), realm); } } ClientAdapter adapter = new ClientAdapter(realm, cached, this); return adapter; }