Uploaded image for project: 'Causeway'
  1. Causeway
  2. CAUSEWAY-1283

SAFE_AND_CACHEABLE semantics caches incorrectly, works for domain services (stateless) but not for domain entities (where stateful target determines result)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.10.0
    • 1.11.0
    • Core
    • None

    Description

      From Oscar, on mailing list:

      I’m experiencing a bad behavior using SAFE_AND_CACHEABLE actions implemented on Domain Entities.

      As current QueryResultsCache implementation has as its Key the calling class, instead of the concrete domain entity that has invoked it, it will return the cached result when invoking the same action on different domain objects.

      For example, I have the following action:

      public class Product {

      // {{ findStockForSupplier (action)
      @Action(semantics = SemanticsOf.SAFE_AND_REQUEST_CACHEABLE)
      @ActionLayout(hidden = Where.ANYWHERE)
      @MemberOrder(name = "supplierTerms", sequence = "3")
      public BigDecimal findStockForSupplier(
      final Supplier supplier)

      { final ProductSupplierTerms productSupplierTerms = this.wrapSkipRules(this).findTermsForSupplier(supplier); return productSupplierTerms != null ? productSupplierTerms.getStock() : BigDecimal.ZERO; }

      }

      If I invoke that action over 2 different Products (ie, Product instances) as per:

      final ProductSupplierTerms productSupplierTerms1 = this.wrapSkipRules(product1).findTermsForSupplier(supplier);

      final ProductSupplierTerms productSupplierTerms2 = this.wrapSkipRules(product2).findTermsForSupplier(supplier);

      For the second invocation it will return the cached result, as only the class is considered on the QueryResultsCache and not the instance “identity”, and both “product1” and “product2” are Product instances.

      As all Domain Entities implement the Comparable interface, perhaps it might be considered.

      Until now, I didn’t noticed this because I always used the QueryResultsCache for Domain Services, and they have only 1 instance in production.

      But it’s not the same when the SAFE_AND_CACHEABLE actions are implemented on Domain Entities.

      Perhaps the solution would be to simply change the QueryResultsCache.Key implementation to accept an Object instead of a Class, using the “Comparable” interface if implemented to differentiate between objects (for Domain Objects), and the “equal” operator when not present (for Services)?

      Attachments

        Activity

          People

            Unassigned Unassigned
            danhaywood Daniel Keir Haywood
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: