This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Run all tests
vendor/bin/pest
# Run a single test file
vendor/bin/pest tests/Unit/TrackerTest.php
# Run a specific test by name
vendor/bin/pest --filter "test name"
# Lint (Laravel Pint)
vendor/bin/pint
# Build CP assets
npm run build
# Dev CP assets
npm run devThis is a Statamic addon (thoughtco/statamic-cache-tracker) that tracks which content items are rendered on each page, then automatically clears those pages from the static cache when content is updated.
-
Tracking —
Http/Middleware/CacheTrackerruns on every GET request. It hooks into Statamic's augmentation lifecycle (viaAsset::hook,Entry::hook,LocalizedTerm::hook, etc.) to collect "tags" for each content item rendered during the request. After a successful response, it stores aURL → [tags]mapping in cache. -
Invalidation —
Listeners/Subscribersubscribes to Statamic save/delete events (entries, assets, terms, navs, forms, globals). When content changes, it dispatchesJobs/InvalidateTagswhich callsTracker::invalidate($tags)to find all URLs containing those tags and clear them from the static cache. -
Tag format — Tags follow patterns like
asset:{id},collection:{handle}:{id},term:{id},form:{handle},nav:{handle},global:{handle}. Wildcard matching is supported via*prefix notation (e.g.,collection:blog:*).
Tracker/Manager— Core logic. StoresURL → tags[]in cache under keytracker::urls. Handlesadd,get,invalidate, andflush. Tag matching supports wildcards.Http/Middleware/CacheTracker— Hooks into Statamic augmentation to collect tags during rendering. Also firesTrackContentTagsevent for custom integrations.Listeners/Subscriber— Maps Statamic events to tag generation and queues invalidation.Facades/Tracker— Facade forManager(bound ascache-tracker).
Custom tag sources can be registered via Tracker::addAdditionalTracker(), which accepts a closure or class with an __invoke(Request $request, array &$tags) signature and runs in a pipeline.
The TrackContentTags event can be fired from custom code to inject additional tags into the current request's tracking.
- Utility — "Cache Tracker" utility in the CP for manually clearing URLs or wildcards.
- Bulk Actions — "View Cache Tags" and "Clear Cache" actions available on entry/term listings.
- Permissions —
view cache tracker tagsandclear cache tracker tags.
Tests use Pest with an AddonTestCase base that:
- Enables static caching with
halfstrategy - Creates a default
pagescollection with ahomeentry - Disables stache disk writes
- Uses SQLite in-memory database
Fixture views live in tests/__fixtures__/resources/views/.