private Set<Document> supportedDocuments() { return queryResultsCache.execute(new Callable<Set<Document>>() { @Override public Set<Document> call() throws Exception { return supportedDocumentsNoCache(supportingDocumentCandidate); } }, Document_supports.class, "supportedDocuments", supportingDocumentCandidate); }
@Programmatic public <T> T execute(final Callable<T> callable, final Class<?> callingClass, final String methodName, final Object... keys) { if(control.isFixturesInstalling()) { try { return callable.call(); } catch (Exception e) { throw new RuntimeException(e); } } final Key cacheKey = new Key(callingClass, methodName, keys); return executeWithCaching(callable, cacheKey); }
protected <T> T executeWithCaching(final Callable<T> callable, final Key cacheKey) { try { final Value<?> cacheValue = cache.get(cacheKey); logHitOrMiss(cacheKey, cacheValue); if(cacheValue != null) { return (T) cacheValue.getResult(); } // cache miss, so get the result... T result = callable.call(); // ... and cache // // (it is possible that the callable just invoked might also have updated the cache, eg if there was // some sort of recursion. However, Map#put(...) is idempotent, so valid to call more than once. // // note: there's no need for thread-safety synchronization... remember that QueryResultsCache is @RequestScoped put(cacheKey, result); return result; } catch (Exception e) { throw new RuntimeException(e); } }
private static void logHitOrMiss(final Key cacheKey, final Value<?> cacheValue) { if(!LOG.isDebugEnabled()) { return; } LOG.debug("{}: {}", (cacheValue != null ? "HIT" : "MISS"), cacheKey.toString()); }
@Programmatic @SuppressWarnings("unchecked") public <T> T execute(final Callable<T> callable, final Key cacheKey) { if(control.isFixturesInstalling()) { try { return callable.call(); } catch (Exception e) { throw new RuntimeException(e); } } return executeWithCaching(callable, cacheKey); }
@Before public void setUp() throws Exception { queryResultsCache = new QueryResultsCache(); control = new QueryResultsCache.Control(); queryResultsCache.control = control; }
@Before public void setUp() throws Exception { queryResultsCache = new QueryResultsCacheInternal(); control = new QueryResultsCacheControlInternal() { { eventBusService = new EventBusServiceDefault() { { allowLateRegistration = true; eventBusImplementation = eventBusImplementationAxon = new EventBusPluginForAxon(); } }; } }; control.postConstruct(); queryResultsCache.control = control; }
@Programmatic @SuppressWarnings("unchecked") public <T> Value<T> get(final Key cacheKey) { Value<T> value = (Value<T>) cache.get(cacheKey); logHitOrMiss(cacheKey, value); return value; }
private Set<Document> supportedDocuments() { return queryResultsCache.execute(new Callable<Set<Document>>() { @Override public Set<Document> call() throws Exception { return supportedDocumentsNoCache(supportingDocumentCandidate); } }, Document_supports.class, "supportedDocuments", supportingDocumentCandidate); }
@Programmatic public UserSetting find( final String user, final String key) { return queryResultsCache.execute(new Callable<UserSetting>() { @Override public UserSetting call() throws Exception { return doFind(user, key); } }, UserSettingRepository.class, "find", user, key); }
@Programmatic public ApplicationSetting find(final String key) { return queryResultsCache.execute(new Callable<ApplicationSetting>() { @Override public ApplicationSetting call() throws Exception { return doFind(key); } }, ApplicationSettingRepository.class, "find", key); }
public List<Document> choices0Exec() { return queryResultsCache.execute(() -> findAttachedToDocumentsNoCache(), Document_removeAttachment.class, "choices0Exec", document); }
public List<Document> choices0Exec() { return queryResultsCache.execute(() -> findAttachedToDocumentsNoCache(), Document_removeAttachment.class, "choices0Exec", document); }
/** * All templates which are applicable to the domain object's atPath, and which can be created and attached to at * least one domain object. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForCreateAndAttach(domainObject), getClass(), "$$", domainObject); }
/** * All templates which are applicable to the domain object's atPath, and which can be created and attached to at * least one domain object. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForCreateAndAttach(domainObject), getClass(), "$$", domainObject); }
/** * All templates which are applicable to the domain object's atPath, and which can be previewed. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForPreview(domainObject), getClass(), "$$", domainObject); }
/** * All templates which are applicable to the domain object's atPath, and which can be previewed. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForPreview(domainObject), getClass(), "$$", domainObject); }
/** * All templates which are applicable to the domain object's atPath, and which can be created and attached to at * least one domain object. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForCreateAndAttach(domainObject), getClass(), "$$", domainObject); }
/** * All templates which are applicable to the domain object's atPath, and which can be created and attached to at * least one domain object. */ public List<DocumentTemplate> choices0$$() { return queryResultsCache.execute( () -> documentTemplateService.documentTemplatesForCreateAndAttach(domainObject), getClass(), "$$", domainObject); }