@Override public ClientModel getClientById(String id, RealmModel realm) { CachedClient cached = cache.get(id, CachedClient.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached != null) { logger.tracev("client by id cache hit: {0}", cached.getClientId()); } if (cached == null) { Long loaded = cache.getCurrentRevision(id); ClientModel model = getClientDelegate().getClientById(id, realm); if (model == null) return null; ClientModel adapter = cacheClient(realm, model, loaded); managedApplications.put(id, adapter); return adapter; } else if (invalidations.contains(id)) { return getRealmDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientModel adapter = validateCache(realm, cached); managedApplications.put(id, adapter); return adapter; }
@Override public ClientModel getClientByClientId(String clientId, RealmModel realm) { String cacheKey = getClientByClientIdCacheKey(clientId, realm.getId()); ClientListQuery query = cache.get(cacheKey, ClientListQuery.class); String id = null; if (query != null) { logger.tracev("client by name cache hit: {0}", clientId); } if (query == null) { Long loaded = cache.getCurrentRevision(cacheKey); ClientModel model = getClientDelegate().getClientByClientId(clientId, realm); if (model == null) return null; if (invalidations.contains(model.getId())) return model; id = model.getId(); query = new ClientListQuery(loaded, cacheKey, realm, id); logger.tracev("adding client by name cache miss: {0}", clientId); cache.addRevisioned(query, startupRevision); } else if (invalidations.contains(cacheKey)) { return getClientDelegate().getClientByClientId(clientId, realm); } else { id = query.getClients().iterator().next(); if (invalidations.contains(id)) { return getClientDelegate().getClientByClientId(clientId, realm); } } return getClientById(id, realm); }
boolean queryDB = invalidations.contains(cacheKey) || listInvalidations.contains(realm.getId()); if (queryDB) { return getClientDelegate().getClients(realm); List<ClientModel> model = getClientDelegate().getClients(realm); if (model == null) return null; Set<String> ids = new HashSet<>();
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; }