• Stars
    star
    140
  • Rank 252,075 (Top 6 %)
  • Language
    PHP
  • License
    Other
  • Created about 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WordPress plugin for partial and async caching.

Fragment Cache

Scrutinizer Code Quality

Fragment Cache is a WordPress plugin for partial and async caching of heavy front-end elements. It currently supports caching navigation menus, widgets, and galleries.

Caching is built on top of transients API (with enhancements provided by TLC Transients library), provides soft expiration and transparent object cache support.

Installation

Download plugin archive from releases section.

Or install in plugin directory via Composer:

composer create-project rarst/fragment-cache --no-dev

Frequently Asked Questions

Why fragments don't recognize logged in users / current page?

Fragment Cache implements soft expiration - when fragments expire, they are regenerated asynchronously and do not take time in front end page load. The side effect is that it is impossible to preserve context precisely and in generic way.

Fragments that must be aware of users or other context information should be excluded from caching or handled by custom implementation, that properly handles that specific context.

How to disable caching?

Disable handler

Caching for the fragment type can be disabled by manipulating main plugin object:

global $fragment_cache;

// completely remove handler, only use before init
unset( $fragment_cache['widget'] );

// or disable handler, use after init
$fragment_cache['widget']->disable();

Skip individual fragments

Caching for individual fragments can be disabled by using fc_skip_cache hook.

add_filter( 'fc_skip_cache', function ( $skip, $type, $name, $args, $salt ) {

	// Widget by class.
	if ( 'widget' === $type && is_a( $args['callback'][0], 'WP_Widget_Meta' ) ) {
		return true;
	}

	// Menu by theme location.
	if ( 'menu' === $type && isset( $args['theme_location'] ) && 'header' === $args['theme_location'] ) {
		return true;
	}

	// Menu by name.
	if ( 'menu' === $type && isset( $args['menu'] ) ) {

		if ( 'Menu with login' === $args['menu'] ) {
			return true;
		}

		if ( is_a( $args['menu'], 'WP_Term' ) && 'Menu with login' === $args['menu']->name ) {
			return true;
		}
	}

	// Gallery by ID of post.
	if ( 'gallery' === $type && 123 === $args['post_id'] ) {
		return true;
	}

	return $skip;
}, 10, 5 );

License Info

Fragment Cache own code is licensed under GPLv2+ and it makes use of code from:

  • Composer (MIT)
  • Pimple (MIT)
  • TLC Transients (GPLv2+)

More Repositories

1

laps

Light WordPress profiler.
PHP
535
star
2

release-belt

Composer repository implementation for ZIPs.
PHP
161
star
3

wps

WordPress plugin for whoops error handler.
PHP
125
star
4

meadow

WordPress templating DSL based on Twig.
PHP
73
star
5

wporg-client

Standalone HTTP client for public WordPress.org API.
PHP
70
star
6

wpdatetime

Extension of PHP’s DateTime and DateTimeZone classes for WordPress context.
PHP
63
star
7

update-blocker

Lightweight generic blocker of updates from official WordPress repositories.
PHP
54
star
8

hybrid-wing

Toolkit theme for WordPress, based on Hybrid Core and Twitter Bootstrap.
PHP
30
star
9

error-log-dashboard-widget

Robust zero-configuration and low-memory WordPress plugin to keep an eye on error log.
PHP
30
star
10

advanced-hooks-api

Set of (experimental) wrappers that allow to hook more elaborate WordPress events without coding intermediary functions
PHP
28
star
11

phpcs-cognitive-complexity

Cognitive Complexity implementation for PHP_CodeSniffer
PHP
24
star
12

toolbar-theme-switcher

Adds WordPress toolbar menu that allows users to switch theme for themselves.
PHP
19
star
13

composer-in-wp

Composer in WordPress site source
Ruby
16
star
14

wprss2hugo

WordPress eXtended RSS to Hugo importer.
PHP
10
star
15

seam

Lightweight site renderer for Markdown content and Twig templates
PHP
5
star
16

ComposePOT

WordPress MakePOT reboot.
PHP
5
star
17

locate-vendor

Helper for vendor directory location in Composer.
PHP
5
star
18

dnd-lookup

A small search web app for D&D 5e SRD
Vue
4
star
19

holder-wp

Quick and flexible placeholders, created right in browser.
PHP
4
star
20

php-calendar

Calendar feeds for PHP versions releases and support.
HTML
2
star
21

chill-config

Experimental YAML config handler for WordPress
PHP
2
star
22

sg-cachepress

The SG CachePress is a plugin that allows you to use the SiteGround dynamic cache and Memcached to optimize the performance of your WordPress.
PHP
2
star
23

github-actions-for-ci

JavaScript
1
star