GitXplorerGitXplorer
s

tiny-cache

public
27 stars
4 forks
2 issues

Commits

List of commits on branch master.
Verified
3d2d060e0167bd732be538c7cefc451667defe9d

Update README.md

sszepeviktor committed 2 years ago
Unverified
c0c9804a935258ce6c591304855488b92ebfcca5

Fix all types

sszepeviktor committed 3 years ago
Unverified
2fc44b22e8c8010c8a061b907b9dc52ce6595a6b

Fix tests

sszepeviktor committed 3 years ago
Unverified
4ebaf58000750cf553d72a542792a4f5fed38bd9

Merge branch 'master' of github.com:szepeviktor/tiny-cache

sszepeviktor committed 3 years ago
Unverified
69f4112dcb4b49949406f8b26eaa237be183edd4

Improvements

sszepeviktor committed 3 years ago
Verified
a44fe351f3687548c151d9249706e291917cb16a

Fixes (#4)

ccolinleroy committed 3 years ago

README

The README file for this repository.

Tiny cache

Cache post content, translations and nav menu output in persistent object cache.

This MU plugin works well in production providing you understand its source code (133 sloc).

WordPress performance

Please see https://github.com/szepeviktor/wordpress-website-lifecycle/blob/master/WordPress-performance.md

Usage

Of course you need persistent object cache. Consider Redis server and wp-redis plugin.

Replace the_content() calls in your theme.

NOTICE Replace only argument-less calls! $more_link_text and $strip_teaser are not supported.

find -type f -name "*.php" | xargs -r -L 1 sed -i -e 's|\bthe_content();|the_content_cached();|g'

No-cache situations

  • wp_suspend_cache_addition( true );
  • define( 'DONOTCACHEPAGE', true );

Prevent missing plugin

Protection against plugin deactivation.

Copy these to your theme's functions.php.

    if ( ! function_exists( 'the_content_cached' ) ) {
        function the_content_cached( $more_link_text = null, $strip_teaser = false ) {
            the_content( $more_link_text, $strip_teaser );
        }
    }
    if ( ! function_exists( 'get_the_content_cached' ) ) {
        function get_the_content_cached( $more_link_text = null, $strip_teaser = false ) {
            return get_the_content( $more_link_text, $strip_teaser );
        }
    }
    if ( ! function_exists( 'get_template_part_cached' ) ) {
        function get_template_part_cached( $slug, $name = null, $version_hash = '' ) {
            get_template_part( $slug, $name );
        }
    }

Little sisters

  1. Tiny navigation menu cache - for nav menu output
  2. Tiny translation cache - for translations (.mo files)

Alternative

https://github.com/Rarst/fragment-cache