PHP code example of inpsyde / menu-cache

1. Go to this page and download the library: Download inpsyde/menu-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inpsyde / menu-cache example snippets




add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION, function () {

	// Cache menus for 10 minutes.
	return 600;
} );



add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_KEY, function ( $key, $args ) {

	// Construct the key based on the theme location only.
	return "cached_menu_{$args->theme_location}";
}, 10, 2 );



add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_KEY_ARGUMENT, function () {

	// Use argument name with a leading underscore.
	return '_menu_key';
} );



add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_SHOULD_CACHE_MENU, function ( $should_cache_menu, $args ) {

	// Cache all menus for a bunch of dynamically created theme locations.
	return 0 === strpos( $args->theme_location, 'some_prefix_here_' );
}, 10, 2 );



add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_THEME_LOCATIONS, function () {

	// Cache the menus for the "primary" theme location only.
	return 'primary';
} );