Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postDate is not respected as cache TTL #187

Open
michielroding opened this issue Mar 12, 2024 · 2 comments
Open

postDate is not respected as cache TTL #187

michielroding opened this issue Mar 12, 2024 · 2 comments
Labels

Comments

@michielroding
Copy link

Description

When an Entry has a postDate in the future (pending) the \craft\base\Element::@$enabledForSite is disabled.

Once the postDate is in the past this (and other fields) becomes enabled, but the API will still return the old disabled value. Adding a random cache-busting query parameter to the API call will return the correct new state.

We use Craft as a headless CMS and want to be able to schedule articles in the future. However the cache isn't expired when the postDate is in the past.

Steps to reproduce

  1. Create an Entry that will be published in the future
  2. Request the Entry via the API with the criteria status set to [Entry::STATUS_LIVE, Entry::STATUS_PENDING]
  3. Observe the enabledForSite state being false
  4. Wait for the Entry to become public
  5. Refetch the data via the API
  6. The enabledForSite is still reported as false
  7. Of course all other data is also stale; the status etc etc

Additional info

  • Craft version: 4.8.1
  • PHP version: 8.1
  • Database driver & version: mysql 5.7
  • Plugins & versions: Element API 3.0.1.1
@brandonkelly
Copy link
Member

Thanks for reporting that!

Just released Element API 4.1.0 with a fix for this. Now caches are no longer stored beyond the lowest expiry date from the results.

@brandonkelly brandonkelly reopened this Mar 14, 2024
@brandonkelly
Copy link
Member

Sorry, just realized you are talking about post dates, not expiry dates. I’ll have to think a bit more on that one, as we don’t currently have any code in place for restricting cache durations based on post date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants