}
@Override
public OAuthClientModel getOAuthClientById(String id, RealmModel realm) {
if (!cache.isEnabled()) return getDelegate().getOAuthClientById(id, realm);
CachedOAuthClient cached = cache.getOAuthClient(id);
if (cached != null && !cached.getRealm().equals(realm.getId())) {
cached = null;
}
if (cached == null) {
OAuthClientModel model = getDelegate().getOAuthClientById(id, realm);
if (model == null) return null;
if (clientInvalidations.contains(id)) return model;
cached = new CachedOAuthClient(cache, getDelegate(), realm, model);
cache.addCachedOAuthClient(cached);
} else if (clientInvalidations.contains(id)) {
return getDelegate().getOAuthClientById(id, realm);
} else if (managedClients.containsKey(id)) {
return managedClients.get(id);