Skip to content

Conversation

@zigzagdev
Copy link
Contributor

@zigzagdev zigzagdev commented Dec 15, 2025

Description

This PR fixes the behavior of MongoStore::increment() so that expired cache entries are no longer incremented.

what has changed

  • Before changed
    • Increment the value first
    • Then check whether the cache entry was expired
    • Potentially delete the entry afterward

This caused expired cache values to be modified briefly, which is inconsistent with Laravel’s cache semantics.

  • The method now:
    • Filters out expired entries at the query level using expires_at > now
    • Returns false when the cache entry is missing or expired
    • Avoids modifying expired values entirely

Test Results

スクリーンショット 2025-12-15 10 39 13
  • A regression test was added to proved that
    • increment() returns false for expired cache entries
    • The stored value remains unchanged when the cache is already expired

Checklist

  • Add tests and ensure they pass

Copilot AI review requested due to automatic review settings December 15, 2025 01:53
@zigzagdev zigzagdev requested a review from a team as a code owner December 15, 2025 01:53
@zigzagdev zigzagdev requested a review from alcaeus December 15, 2025 01:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in MongoStore::increment() where expired cache entries were being incremented before being checked for expiration, causing inconsistent behavior with Laravel's cache semantics.

Key Changes:

  • Modified the increment query to filter expired entries at the database level using expires_at > now
  • Removed the post-increment expiration check that was deleting entries after they were modified
  • Added regression test to verify expired entries are not incremented and remain unchanged

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Cache/MongoStore.php Updated increment() method to filter expired entries in the query filter instead of checking expiration after incrementing the value
tests/Cache/MongoCacheStoreTest.php Added assertion to verify that expired cache entries remain unchanged when increment is attempted

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant