PHPackages                             devjio/statamic-fragment-cache - 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. [Caching](/categories/caching)
4. /
5. devjio/statamic-fragment-cache

ActiveStatamic-addon[Caching](/categories/caching)

devjio/statamic-fragment-cache
==============================

Statamic Fragment Cache addon

11PHP

Since Aug 5Pushed 9mo agoCompare

[ Source](https://github.com/techgonia-devjio/statamic-fragment-cachye)[ Packagist](https://packagist.org/packages/devjio/statamic-fragment-cache)[ RSS](/packages/devjio-statamic-fragment-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Statamic Fragment Cache
=======================

[](#statamic-fragment-cache)

Introduction
------------

[](#introduction)

The Statamic Fragment Cache is caching addon for Statamic, engineered to enhance site performance through a granular, dependency-aware caching methodology.

### Core Concept

[](#core-concept)

Conventional full-page caching strategies, while performant, often lack the flexibility required for dynamic websites. When a piece of content is updated, it can be difficult and inefficient to determine which cached pages have become stale, frequently leading to serving outdated information to users.

This package addresses that challenge by implementing a granular caching system. It provides a set of Antlers tags that allow developers to wrap discrete sections of a template—such as modules/block(in page builder context) or partials—in a cache block. These blocks are dependency-aware, meaning they maintain a record of the content entries they rely upon for rendering.

Consequently, when a source entry is modified, the addon can target and invalidate only the dependent cached fragments. This approach combines the performance benefits of caching with the data integrity of a fully dynamic site.

How to Install
--------------

[](#how-to-install)

#### via composer as package

[](#via-composer-as-package)

You can install this addon via Composer:

```
composer require Devjio/statamic-fragment-cache
```

#### as addon directory

[](#as-addon-directory)

Place the addon directory into addons/devjio/statamic-fragment-cache.

Add the addon as a "path" repository to your project's composer.json file:

```
{
    ...
  "repositories": [
    {
        "type": "path",
        "url": "addons/devjio/statamic-fragment-cache"
    }
  ],
  "require": {
     ....,
    "devjio/statamic-fragment-cache": "@dev"
  }
```

Execute `composer require devjio/statamic-fragment-cache` in your terminal.

#### as git submodule

[](#as-git-submodule)

TODO: ....

Optionally, publish the configuration file to config/statamic/fragment-cache.php to override default settings:

php artisan vendor:publish --tag=fragment-cache-config

Key Features
------------

[](#key-features)

- **Dependency-Aware Invalidation**: The system listens for entry-saving events and purges only the cached fragments that are dependent on the modified entry.
- **Fragment Exclusion ("Donut Caching")**: A provided {{ ignore\_cache }} tag allows developers to exclude dynamic sections, such as navigation menus or user-specific blocks, from within a larger cached fragment.
- **Optimized Live Preview**: The addon ensures an efficient and accurate editing experience. Unchanged modules on a page are served from a temporary cache for speed, while the module being actively edited updates in real-time.
- **Zero-Dependency Architecture**: The package is designed to function seamlessly with Statamic's file-based architecture and does not require external services such as Redis, a database, or other server software.
- **Extensive Configuration**: A configuration file provides control over all aspects of the addon, including cache durations, key-naming conventions, logging, and invalidation rules.
- **Logging**: Optional logging features are included to provide detailed insight into cache hits, misses, and content generation times, which is valuable for debugging and performance analysis.

Usage
-----

[](#usage)

There are three types of cache tags:

- CacheModule
- CacheFragment
- IgnoreCache

#### Caching a Module

[](#caching-a-module)

The primary use case involves caching individual modules within a page builder context. To do this, wrap the module's partial render in the {{ cache\_module }} tag and provide the parent entry's ID.

```
{{# It is recommended to store the entry's ID before the loop #}}
{{ _entry_id = id }}

{{ modules }}
{{# The tag automatically generates a unique key from the module and parent context #}}
{{ cache_module entry_id="{_entry_id}" }}
{{ partial src="partials/modules/{type}" }}
{{ /cache_module }}
{{ /modules }}
```

#### Caching a Generic Fragment

[](#caching-a-generic-fragment)

For caching arbitrary template sections, such as a site header or footer, use the {{ cache\_fragment }} tag. This tag requires a unique key parameter.

```
{{# Example of caching the site footer #}}
{{ cache_fragment key="site_footer" }}
{{ partial:layout/footer }}
{{ /cache_fragment }}
```

### Dependency Watching (watch parameter)

[](#dependency-watching-watch-parameter)

The watch parameter instructs a cached fragment to be invalidated when a separate, specified entry is updated.

1. Automatic Watching (watch="true")

This mode tries to automatic dependency detection, depending on config. The tag will inspect the current context for an array of entries (as defined by the auto\_watch\_variables config key) and will automatically watch all entries found within it. This is ideal for parent pages that render lists of their children.

```
{{# This module displays a list of child pages #}}

{{ modules }}
{{# The tag automatically generates a unique key from the module and parent context #}}
    {{ cache_module entry_id="{_entry_id}" watch="true" }}
        {{# The cache module will look for children prop(bcuz defined in config) for entries and watch them if they changed in future(on entry saved this will delete the exiting cache this entry and related) #}}
        {{ partial src="partials/modules/{type}" }}
    {{ /cache_module }}
{{ /modules }}
```

2. Manual Watching

For more complex relationships, such as a curated list of related entries, a pipe-separated string of entry IDs may be provided for explicit dependency tracking.

```
{{# Manually construct a list of entry tags to watch #}}
{{ _watch_list = "" }}
{{ children }}
{{ _watch_list = "{_watch_list}|entry:{id}" }}
{{ /children }}

{{ cache_fragment key="related-articles" watch="{_watch_list}" }}
{{# ... render related articles content ... #}}
{{ /cache_fragment }}
```

3. Fragment Exclusion (ignore\_cache) To prevent a dynamic section within a larger cached block from being cached, wrap the dynamic content in {{ ignore\_cache }} tags. This technique is particularly effective for components like navigation menus that must be rendered fresh on every request. I.e if you have language switch, it will cache the language dropdown links permanently the same page and will redirect on the same even if you are on the different page wants to change the language of that page.

```
{{ cache_fragment key="site_header" }}
{{# This outer content is static and will be cached #}}

...
        {{# This inner block is dynamic and will be rendered on every request #}}
        {{ ignore_cache }}
            {{ partial:navigation/language_switch }}
        {{ /ignore_cache }}

{{ /cache_fragment }}
```

### Configuration

[](#configuration)

The addon's settings can be configured by publishing the config file to config/statamic/fragment-cache.php.

KeyDescriptionenabledA master switch to enable or disable the entire addon.prefixesAn array of prefixes for cache keys to prevent naming collisions.default\_durationThe default cache lifetime (e.g., '1 week'). A null value caches items indefinitely until invalidated.auto\_watch\_variablesAn array of variable names the tag will inspect when watch="true".invalidation.enabledEnables or disables the automatic cache invalidation listener.invalidation.invalidate\_static\_cacheIf true, the addon will also clear Statamic's static page cache (half/full strategies).live\_preview.detect\_usingThe method for detecting Live Preview ('header' or 'context').loggingConfiguration for enabling, setting the channel, and defining the level for debug logging.### Future Roadmap

[](#future-roadmap)

The following enhancements are planned for future releases of the package:

- **Surgical Flushing**: Implement logic to invalidate only the specific modules that have actually changed within an entry, rather than all modules on that entry, for improved performance on content-heavy pages.
- **Cache Warming Command**: Introduce an Artisan command (php please fragment-cache:warm) to proactively generate the cache for all site pages.("Brutal" way: create thread pool and call all sitemap urls)
- **Broader Invalidation**: Add event listeners for TermSaved, GlobalSetSaved, and other data types to provide more comprehensive cache invalidation.
- **Dashboard Widget**: Develop a Statamic control panel widget to display cache statistics, such as hit/miss ratios and cache sizes, single entry cache size, deletable, and more.
- **Database Support**: Currently, only file-based caching is supported. Need to test and implement database caching for larger sites with high traffic.
- **invalidate cache**
-

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance41

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8fbdcf829b4975e4c3f380879cc9c8543ba3c3829a1bfe01085d2c44a4f873c?d=identicon)[Phoenix404](/maintainers/Phoenix404)

---

Top Contributors

[![mani-repos-link](https://avatars.githubusercontent.com/u/13603818?v=4)](https://github.com/mani-repos-link "mani-repos-link (1 commits)")

### Embed Badge

![Health badge](/badges/devjio-statamic-fragment-cache/health.svg)

```
[![Health](https://phpackages.com/badges/devjio-statamic-fragment-cache/health.svg)](https://phpackages.com/packages/devjio-statamic-fragment-cache)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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