Skip to content

feat: add clearCache() to purge cache without sending a request - #17

Merged
Sammyjo20 merged 2 commits into
saloonphp:v3from
jornicornelese:feat/delete-cache-without-request
Sep 18, 2026
Merged

Sammyjo20 merged 2 commits into
saloonphp:v3from
jornicornelese:feat/delete-cache-without-request

Conversation

@jornicornelese

Copy link
Copy Markdown
Contributor

Summary

Currently, invalidateCache() only takes effect inside CacheMiddleware, meaning the cache is only refreshed when a request is actually sent. There's no way to just delete a cached response without making an API call.

In my own application I ran into redundant API calls — I only wanted to invalidate the cache, not immediately retrieve fresh data. This PR adds a deleteCache() method to the HasCaching trait that deletes the cached response directly, without going through the middleware pipeline.

Usage

// From the request
$request = new GetUserRequest($id);
$request->deleteCache($connector);

// From the connector
$connector->deleteCache(new GetUserRequest($id));

Changes

  • Added deleteCache(Connector|Request $counterpart) to HasCaching
  • Builds the same cache key as CacheMiddleware (including custom cacheKey() overrides)
  • Calls Driver::delete() directly — no existing code modified
  • 5 new Pest tests

jornicornelese and others added 2 commits March 18, 2026 22:51
Adds a deleteCache() method to the HasCaching trait that allows
deleting a cached response without going through the middleware
pipeline. Useful for applications that only want to delete the
cache without immediately retrieving fresh data.

@Sammyjo20 Sammyjo20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @jornicornelese - great idea! I've tweaked the implementation a little bit and I've renamed it to clearCache.

@Sammyjo20 Sammyjo20 changed the title feat: add deleteCache() to purge cache without sending a request feat: add clearCache() to purge cache without sending a request Sep 18, 2026
@Sammyjo20
Sammyjo20 merged commit 5a036ba into saloonphp:v3 Sep 18, 2026
9 checks passed
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