{"id":13534717,"url":"https://github.com/inpsyde/menu-cache","last_synced_at":"2025-04-02T00:30:33.499Z","repository":{"id":56991889,"uuid":"71801294","full_name":"inpsyde/menu-cache","owner":"inpsyde","description":"Easily cache rendered menus using the Transients API.","archived":true,"fork":false,"pushed_at":"2019-12-10T12:19:42.000Z","size":38,"stargazers_count":72,"open_issues_count":1,"forks_count":5,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-02-26T09:08:35.210Z","etag":null,"topics":["cached-menus","transients-api","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/inpsyde/menu-cache","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inpsyde.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-24T15:09:04.000Z","updated_at":"2024-07-17T12:44:25.000Z","dependencies_parsed_at":"2022-08-21T09:10:47.559Z","dependency_job_id":null,"html_url":"https://github.com/inpsyde/menu-cache","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inpsyde%2Fmenu-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inpsyde%2Fmenu-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inpsyde%2Fmenu-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inpsyde%2Fmenu-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inpsyde","download_url":"https://codeload.github.com/inpsyde/menu-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246734825,"owners_count":20825210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cached-menus","transients-api","wordpress","wordpress-plugin"],"created_at":"2024-08-01T08:00:37.358Z","updated_at":"2025-04-02T00:30:33.217Z","avatar_url":"https://github.com/inpsyde.png","language":"PHP","funding_links":[],"categories":["Caching Helping Plugins"],"sub_categories":[],"readme":"# Inpsyde Menu Cache\n\n[![Version](https://img.shields.io/packagist/v/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)\n[![Status](https://img.shields.io/badge/status-active-brightgreen.svg)](https://github.com/inpsyde/menu-cache)\n[![Build](https://img.shields.io/travis/inpsyde/menu-cache.svg)](http://travis-ci.org/inpsyde/menu-cache)\n[![Downloads](https://img.shields.io/packagist/dt/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)\n[![License](https://img.shields.io/packagist/l/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)\n\n\u003e Easily cache rendered menus using the Transients API.\n\n## Introduction\n\nThe `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.\nWith lots of taxonomies, terms and menu items, this can lead to a fair amount of (totally redundant) database queries.\n\nThis plugin lets you cache rendered menus (assuming they don't have dynamic components) for re-use.\n\n## Installation\n\nInstall with [Composer](https://getcomposer.org):\n\n```sh\n$ composer require inpsyde/menu-cache\n```\n\n### Requirements\n\nThis package requires PHP 5.4 or higher.\n\n## Usage\n\nOnce activated, the plugin caches **all** menus, by default for **five minutes**.\nThe menus to be cached, as well as the expiration, can be customized by using the appropriate filter.\n\n### Filters\n\nNeed to customize anything?\nJust use the provided filters.\n\n**Please note:** when you use the below class constants for the filters, make sure that the class is actually available.\nThis can be as easy as _guarding_ your customization with `if ( class_exists( 'Inpsyde\\MenuCache\\MenuCache' ) )`.\n\n#### `Inpsyde\\MenuCache\\MenuCache::FILTER_EXPIRATION`\n\nThe `Inpsyde\\MenuCache\\MenuCache::FILTER_EXPIRATION` filter allows you to define the expiration for all cached menus.\nThe default value is 300, which is 5 minutes.\n\n**Arguments:**\n\n- `int` `$expiration`: Expiration in seconds.\n\n**Usage Example:**\n\n```php\n\u003c?php\n\nadd_filter( \\Inpsyde\\MenuCache\\MenuCache::FILTER_EXPIRATION, function () {\n\n\t// Cache menus for 10 minutes.\n\treturn 600;\n} );\n```\n\n#### `Inpsyde\\MenuCache\\MenuCache::FILTER_KEY`\n\nThe `Inpsyde\\MenuCache\\MenuCache::FILTER_KEY` filter allows you to customize the cache key on a per-menu basis.\nThe default value is constructed using a predfined prefix and the MD5 hash of the serialized args object.\n\n**Arguments:**\n\n- `string` `$key`: Current key.\n- `object` `$args`: Menu args.\n\n**Usage Example:**\n\n```php\n\u003c?php\n\nadd_filter( \\Inpsyde\\MenuCache\\MenuCache::FILTER_KEY, function ( $key, $args ) {\n\n\t// Construct the key based on the theme location only.\n\treturn \"cached_menu_{$args-\u003etheme_location}\";\n}, 10, 2 );\n```\n\n#### `Inpsyde\\MenuCache\\MenuCache::FILTER_KEY_ARGUMENT`\n\nThe `Inpsyde\\MenuCache\\MenuCache::FILTER_KEY_ARGUMENT` filter allows you to customize the menu argument name that is used to store the menu key (for later look-up).\n\n**Arguments:**\n\n- `string` `$key_argument`: Current key argument name.\n\n**Usage Example:**\n\n```php\n\u003c?php\n\nadd_filter( \\Inpsyde\\MenuCache\\MenuCache::FILTER_KEY_ARGUMENT, function () {\n\n\t// Use argument name with a leading underscore.\n\treturn '_menu_key';\n} );\n```\n\n#### `Inpsyde\\MenuCache\\MenuCache::FILTER_SHOULD_CACHE_MENU`\n\nThe `Inpsyde\\MenuCache\\MenuCache::FILTER_SHOULD_CACHE_MENU` filter allows you to customize caching on a per-menu basis.\n\n**Arguments:**\n\n- `bool` `$key`: Whether or not the menu should be cached.\n- `object` `$args`: Menu args.\n\n**Usage Example:**\n\n```php\n\u003c?php\n\nadd_filter( \\Inpsyde\\MenuCache\\MenuCache::FILTER_SHOULD_CACHE_MENU, function ( $should_cache_menu, $args ) {\n\n\t// Cache all menus for a bunch of dynamically created theme locations.\n\treturn 0 === strpos( $args-\u003etheme_location, 'some_prefix_here_' );\n}, 10, 2 );\n```\n\n#### `Inpsyde\\MenuCache\\MenuCache::FILTER_THEME_LOCATIONS`\n\nThe `Inpsyde\\MenuCache\\MenuCache::FILTER_THEME_LOCATIONS` filter allows you to define theme locations to restrict caching menus to.\n\n**Arguments:**\n\n- `string|string[]` `$theme_locations`: One or more theme locations.\n\n**Usage Example:**\n\n```php\n\u003c?php\n\nadd_filter( \\Inpsyde\\MenuCache\\MenuCache::FILTER_THEME_LOCATIONS, function () {\n\n\t// Cache the menus for the \"primary\" theme location only.\n\treturn 'primary';\n} );\n```\n\n## License\n\nCopyright (c) 2017 Inpsyde GmbH\n\nThis code is licensed under the [GPLv2+ License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finpsyde%2Fmenu-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finpsyde%2Fmenu-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finpsyde%2Fmenu-cache/lists"}