Skip to content

FOUR-20944: Implement ETag Caching for Task and Case Data#7786

Merged
eiresendez merged 7 commits intoepic/FOUR-20929from
story/FOUR-20944
Dec 6, 2024
Merged

FOUR-20944: Implement ETag Caching for Task and Case Data#7786
eiresendez merged 7 commits intoepic/FOUR-20929from
story/FOUR-20944

Conversation

@eiresendez
Copy link
Copy Markdown
Contributor

@eiresendez eiresendez commented Dec 2, 2024

Issue & Reproduction Steps

This PR implements ETag caching for all GET and HEAD requests, enhancing performance and reducing bandwidth usage by leveraging HTTP conditional requests. The middleware is now applied globally, ensuring consistent ETag handling across endpoints.

Solution

  1. Global ETag Middleware:
  • Applied the ETag middleware to all GET API requests to ensure consistency and avoid redundant implementation for individual routes.
  • Middleware calculates and validates ETags based on the response or a configurable sources of truth (optional).
  1. Exclude active_at Field:
  • Removed the active_at field from TaskResource and requestor serialization to prevent ETag inconsistencies.
  1. Introduce Configurable ETag Source:
  • updated_at: Default method using database timestamps to determine the latest update for relevant tables.

How to Test

  1. Call any GET endpoint for the first time. A 200 OK response is returned and the content is fetched from the server and cached.
  2. Refresh the page or call the endpoint again. A 304 Not Modified response is returned if the ETag matches.
  3. Modify the relevant data (e.g., update the database). On subsequent requests:
    • If using updated_at as the source, a 200 OK response is returned with the updated content.
  4. Validate that the updated content is cached and subsequent requests return 304 Not Modified.

Related Tickets & Packages

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.

- Process only GET and HEAD methods to ensure middleware relevance and avoid unnecessary processing for non-cacheable HTTP methods.
- Add a check to determine if the response is cacheable, filtering out non-cacheable responses (e.g., those with 'no-store' directive or non-cacheable status codes).
- Default ETag generation now includes user-specific data (auth()->id()) to enforce personalized caching by default.
- Removed 'scope' and 'includeUser' logic for simplified and consistent caching behavior.
- Refactored `EtagManager` to support dynamic ETag generation based on configurable sources (`updated_at`).
- Introduced `generateEtagFromTables` with a `source` parameter for flexibility in determining the source of truth.

This update prepares the app for future scalability and allows switching between different ETag generation strategies.
- Applied ETag middleware to the 'startProcesses' route for improved caching and reduced payload size.
- Added default 'etag_tables' parameter set to 'processes' to optimize ETag generation for this route.
Copy link
Copy Markdown
Contributor

@estebangallego estebangallego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected! 🔥

@processmaker-sonarqube
Copy link
Copy Markdown

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@eiresendez eiresendez merged commit e64f7a7 into epic/FOUR-20929 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants