Hi Oscar,
yes, this makes a lot of sense, and is something I've thought about in the
past myself (though I don't think it's been discussed on the mailing list
before).
In terms of API, it only really makes sense to enable caching for safe
(query-only) actions. So I suggest that it might be better to extend the
ActionSemantics enum:
@Override
@Action(semantics = SemanticsOf.SAFE_AND_REQUEST_CACHED)
public SortedSet<IESG> relevantSnpGenotypes(final IE inputElement,
final Kit kit) {
if (kit != null) {
return
kit.findAllAssociatedSNPGenotypesForInputElement(inputElement,
AlgorithmImplementation.this.IESGClass);
} else {
return Sets.newTreeSet();
}
}
I suggest the word "REQUEST" is in the enum somewhere just so it's obvious
that the caching is only for the duration of a request (rather than session
or something else).
This feature is probably pretty easy to implement. I can do it if you
want, but if you'd like to give it a go I can provide some pointers if you
want?
cheers
Dan
On 10 May 2015 at 12:14, GESCONSULTOR - Óscar Bou <[email protected]>
wrote:
>
>
> Hi all.
>
> We currently have available the
> "org.apache.isis.applib.services.queryresultscache.QueryResultsCache”
> service to cache the result of an Action invocation for the same
> transation.
>
> So if we call a SAFE action that is costly to be computed, many times
> during the same transaction, it’s only computed once, as the 2nd time and
> so on the result will be obtained from a LocalThread cache.
>
> Current usage idiom is something like:
>
> // {{ relevantSnpGenotypes (programmatic - cached)
> @Override
> @Action(semantics = SemanticsOf.SAFE)
> public SortedSet<IESG> relevantSnpGenotypes(final IE inputElement,
> final Kit kit) {
> return this.queryResultsCache.execute(new
> Callable<SortedSet<IESG>>() {
>
> @Override
> public SortedSet<IESG> call() throws Exception {
> if (kit != null) {
> return
> kit.findAllAssociatedSNPGenotypesForInputElement(inputElement,
> AlgorithmImplementation.this.IESGClass);
> } else {
> return Sets.newTreeSet();
> }
> }
>
> }, Kit.class, "relevantSnpGenotypes", inputElement, kit);
> }
>
> // }}
>
>
> // {{ injected: QueryResultsCache
> @Inject
> protected QueryResultsCache queryResultsCache;
>
> // }}
>
>
>
> But perhaps would it be possible to ease its usage by means of an
> annotation ?
>
> Something like:
>
>
> @Action(semantics = SemanticsOf.SAFE, cacheResults = true)
>
>
> If so, the usage idiom would change to simply the action’s code, as the
> one responsible for caching could be a Facet, for example?
>
> // {{ relevantSnpGenotypes (programmatic - cached)
> @Override
> @Action(semantics = SemanticsOf.SAFE, cacheResults = true)
> public SortedSet<IESG> relevantSnpGenotypes(final IE inputElement,
> final Kit kit) {
> if (kit != null) {
> return
> kit.findAllAssociatedSNPGenotypesForInputElement(inputElement,
> AlgorithmImplementation.this.IESGClass);
> } else {
> return Sets.newTreeSet();
> }
> }
>
> // }}
>
>
> Just to know others opinion about if it has sense and if it would be
> possible.
>
> I’m pretty sure this would be one of those “killer functions” for complex
> Domains that would appear on a summary list, despite being currently being
> available.
>
>
>
> Thanks!
>
>
>
> *Óscar Bou Bou*
> Responsable de Producto
> Auditor Jefe de Certificación ISO 27001 en BSI
> CISA, CRISC, APMG ISO 20000, ITIL-F
>
> 902 900 231 / 620 267 520
> http://www.twitter.com/oscarbou
>
> http://es.linkedin.com/in/oscarbou
>
> http://www.GesConsultor.com <http://www.gesconsultor.com/>
>
>
>
> Este mensaje y los ficheros anexos son confidenciales. Los mismos
> contienen información reservada que no puede ser difundida. Si usted ha
> recibido este correo por error, tenga la amabilidad de eliminarlo de su
> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
> Su dirección de correo electrónico junto a sus datos personales constan en
> un fichero titularidad de Gesdatos Software, S.L. cuya finalidad es la de
> mantener el contacto con Ud. Si quiere saber de qué información disponemos
> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
> dirección: Gesdatos Software, S.L. , Paseo de la Castellana, 153 bajo -
> 28046 (Madrid), y Avda. Cortes Valencianas num. 50, 1ºC - 46015 (Valencia).
> Asimismo, es su responsabilidad comprobar que este mensaje o sus archivos
> adjuntos no contengan virus informáticos, y en caso que los tuvieran
> eliminarlos.
>
>
>
>
>
>