PHPackages                             inpsyde/menu-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. inpsyde/menu-cache

AbandonedArchivedWordpress-plugin[Caching](/categories/caching)

inpsyde/menu-cache
==================

Easily cache rendered menus using the Transients API.

1.4.2(6y ago)7310.7k5[1 issues](https://github.com/inpsyde/menu-cache/issues)GPL-2.0-or-laterPHPPHP &gt;=5.4

Since Oct 24Pushed 6y ago9 watchersCompare

[ Source](https://github.com/inpsyde/menu-cache)[ Packagist](https://packagist.org/packages/inpsyde/menu-cache)[ RSS](/packages/inpsyde-menu-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (7)Versions (9)Used By (0)

Inpsyde Menu Cache
==================

[](#inpsyde-menu-cache)

[![Version](https://camo.githubusercontent.com/042b206bd4d5c73f46a83f4d8f21787ff8b87f05afc65747640e2887b76fb211/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e70737964652f6d656e752d63616368652e737667)](https://packagist.org/packages/inpsyde/menu-cache)[![Status](https://camo.githubusercontent.com/0516d1b16221bb9cbc5f57f91e1f235b1b6aaee353113f6d168996f670c9a75d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617475732d6163746976652d627269676874677265656e2e737667)](https://github.com/inpsyde/menu-cache)[![Build](https://camo.githubusercontent.com/1c89bb8e883cba2393712ccb0a036b6f3b40a9f317aee8174e808d4b4cb2132c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e70737964652f6d656e752d63616368652e737667)](http://travis-ci.org/inpsyde/menu-cache)[![Downloads](https://camo.githubusercontent.com/ce1cd1759489cef75da785b1653e21f8126f7371266d0c97d4e07535ecbd9491/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e70737964652f6d656e752d63616368652e737667)](https://packagist.org/packages/inpsyde/menu-cache)[![License](https://camo.githubusercontent.com/51d75f9a148f755309165d78c79bc9a70c0d49831ede859e20be62e0fd9bd1d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e70737964652f6d656e752d63616368652e737667)](https://packagist.org/packages/inpsyde/menu-cache)

> Easily cache rendered menus using the Transients API.

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

[](#introduction)

The `wp_nav_menu()` function calls `_wp_menu_item_classes_by_context()`, which again, depending on the context, calls `wp_get_object_terms()`, which is **not** cached, multiple times. With lots of taxonomies, terms and menu items, this can lead to a fair amount of (totally redundant) database queries.

This plugin lets you cache rendered menus (assuming they don't have dynamic components) for re-use.

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org):

```
$ composer require inpsyde/menu-cache
```

### Requirements

[](#requirements)

This package requires PHP 5.4 or higher.

Usage
-----

[](#usage)

Once activated, the plugin caches **all** menus, by default for **five minutes**. The menus to be cached, as well as the expiration, can be customized by using the appropriate filter.

### Filters

[](#filters)

Need to customize anything? Just use the provided filters.

**Please note:** when you use the below class constants for the filters, make sure that the class is actually available. This can be as easy as *guarding* your customization with `if ( class_exists( 'Inpsyde\MenuCache\MenuCache' ) )`.

#### `Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION`

[](#inpsydemenucachemenucachefilter_expiration)

The `Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION` filter allows you to define the expiration for all cached menus. The default value is 300, which is 5 minutes.

**Arguments:**

- `int` `$expiration`: Expiration in seconds.

**Usage Example:**

```
