PHPackages                             fahlgrendigital/packages-statamic-static-clean - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fahlgrendigital/packages-statamic-static-clean

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fahlgrendigital/packages-statamic-static-clean
==============================================

Keep Statamic static page cache in sync with url hash cache.

v0.1.1(2mo ago)0137MITPHPPHP ^8.3

Since Jul 3Pushed 9mo agoCompare

[ Source](https://github.com/FahlgrenMortineDigital/packages-statamic-static-clean)[ Packagist](https://packagist.org/packages/fahlgrendigital/packages-statamic-static-clean)[ RSS](/packages/fahlgrendigital-packages-statamic-static-clean/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

🧹 Static Cache Cleaner for Statamic
-----------------------------------

[](#-static-cache-cleaner-for-statamic)

This command (`static-cache:clean`) removes **orphaned static cache files** that remain on disk after Redis has forgotten about them — a common edge case in high-traffic Statamic sites using [full static caching](https://statamic.dev/static-caching#file-driver).

### 🧨 Why this is needed

[](#-why-this-is-needed)

Statamic’s `FileCacher` stores all cached URLs for a site in a single array, saved to Redis under a single key (`statamic:static-cache:urls:`). When multiple requests (e.g. page renders, cache warmers, or invalidations) happen concurrently, they may:

- **Read the current cache index**
- **Modify it (add/remove one URL)**
- **Write the entire array back to Redis**

Because this process is **not atomic**, changes from one process can silently overwrite others. This race condition causes certain pages to **disappear from Redis**, even though their static `.html` files remain on disk.

### 🔒 What about Statamic’s built-in locks?

[](#-what-about-statamics-built-in-locks)

Statamic’s static cache middleware *does* apply a **per-URL file lock** (via Symfony's `LockFactory`) during a web request. This prevents the **same URL** from being rendered by multiple requests at the same time.

However, it does **not** protect the shared Redis key that holds the list of all cached URLs. This Redis write is global and unguarded, which means:

- Concurrent requests to different URLs (`/about`, `/products`) are **not locked against each other**.
- Console commands (e.g. `static:warm`, `invalidateUrl`, or queue jobs) **bypass middleware entirely**, skipping locks.
- Any of these can cause unintentional overwrites of Redis state.

> 🔁 Statamic has **mutex guard rails per page**, but not for the **global Redis index**.

### ❗ The risk

[](#-the-risk)

- Redis says a page is **not cached**.
- But the static `.html` file still exists.
- The web server continues serving the stale page, **bypassing Statamic completely**.

This issue is most common during:

- Bulk imports that trigger repeated invalidations (e.g. `EntrySaved` events)
- Cache warming across many URLs in parallel
- Sites using query string variations (`ignore_query_strings => false`)

### ✅ What this command does

[](#-what-this-command-does)

This command:

1. Uses Statamic’s public APIs (`getUrls()`, `getFilePath()`, etc.) to collect all known cache entries from Redis.
2. Walks the static cache directories to find all existing `.html` files.
3. Deletes any file that **is no longer referenced in Redis**.
4. Optionally removes empty parent directories — with safeguards to **never delete above the static cache root**.

### 💡 Benefits

[](#-benefits)

- Keeps your static cache clean and trustworthy
- Ensures Redis remains the **source of truth**
- Fixes stale page issues without requiring upstream changes
- Safe to run on production — includes `--dry-run` mode

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance70

Regular maintenance activity

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Total

5

Last Release

60d ago

Major Versions

v0.0.2 → 6.x-dev2026-03-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/60dfacae6ab4f80fadfea286b16ad311302ccef2c53d687b25248d242c4b0541?d=identicon)[fahlgren](/maintainers/fahlgren)

---

Top Contributors

[![panda4man](https://avatars.githubusercontent.com/u/3106756?v=4)](https://github.com/panda4man "panda4man (12 commits)")[![lasota](https://avatars.githubusercontent.com/u/5107146?v=4)](https://github.com/lasota "lasota (1 commits)")

---

Tags

laravelcmsstatamicflat file

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fahlgrendigital-packages-statamic-static-clean/health.svg)

```
[![Health](https://phpackages.com/badges/fahlgrendigital-packages-statamic-static-clean/health.svg)](https://phpackages.com/packages/fahlgrendigital-packages-statamic-static-clean)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[statamic/statamic

Statamic

824170.4k](/packages/statamic-statamic)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

2381.5k10](/packages/marcorieser-statamic-livewire)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
