Skip to content

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

Open
jornicornelese wants to merge 1 commit intosaloonphp:v3from
jornicornelese:feat/delete-cache-without-request
Open

feat: add deleteCache() to purge cache without sending a request#17
jornicornelese wants to merge 1 commit intosaloonphp:v3from
jornicornelese:feat/delete-cache-without-request

Conversation

@jornicornelese
Copy link

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

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.
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