cache_get() static public method

static public cache_get ( string $key, string $group = '' ) : mixed
$key string
$group string
return mixed
Beispiel #1
0
 /**
  *
  */
 static function _wp_loaded()
 {
     if (!WPLib::cache_get($cache_key = 'roles_initialized')) {
         self::_initialize_roles();
         WPLib::cache_set($cache_key, true);
     }
 }
Beispiel #2
0
 /**
  * Return number of is use categories on posts.
  *
  * @note Ignores 'Uncategorized'
  *
  * @param array $args
  *
  * @return int|mixed
  */
 function category_count($args = array())
 {
     $category_count = WPLib::cache_get($cache_key = 'category_count');
     if (false === $category_count) {
         $args = wp_parse_args($args, array('fields' => 'ids', 'hide_empty' => 1));
         $categories = get_categories($args);
         WPLib::cache_set($cache_key, $category_count = count($categories), null, 15 * 60);
     }
     return intval($category_count) - 1;
 }
Beispiel #3
0
 /**
  * @return array|mixed
  */
 static function role_classes()
 {
     if (!($role_classes = WPLib::cache_get($cache_key = 'role_classes'))) {
         WPLib::autoload_all_classes();
         $role_classes = array();
         foreach (get_declared_classes() as $user_class) {
             if (!is_subclass_of($user_class, 'WPLib_User_Base')) {
                 continue;
             }
             if ($role_slug = self::get_role_slug_by('class', $user_class)) {
                 $role_classes[$role_slug] = $user_class;
             }
         }
         WPLib::cache_set($cache_key, $role_classes);
     }
     return $role_classes;
 }
Beispiel #4
0
 /**
  * @param string $template
  * @param array $args
  * @return string
  */
 function get_template_html($template, $args = array())
 {
     $cache_key = "wplib_template[{$template}][" . md5(serialize($args)) . ']';
     if (!($output = WPLib::cache_get($cache_key))) {
         ob_start();
         $index = 0;
         foreach ($this->elements() as $element) {
             /**
              * @var WPLib_Item_Base $element
              *
              * @todo Create a interface that would indicate a class has a 'the_template' method.
              *
              */
             $args['index'] = $index++;
             $element->the_template($template, $args);
         }
         WPLib::cache_set($cache_key, $output = ob_get_clean());
     }
     return $output;
 }
Beispiel #5
0
 /**
  * Returns array of class names $base_class children with positive values for $base_class::$contant_name.
  *
  * @param $type
  * @param $constant_name
  * @param $base_class
  *
  * @return string[]
  */
 static function _get_child_classes($type, $constant_name, $base_class)
 {
     if (!($child_classes = WPLib::cache_get($cache_key = "{$type}_classes"))) {
         $child_classes = array();
         foreach (self::site_classes() as $class_name) {
             do {
                 if (!is_subclass_of($class_name, $base_class)) {
                     continue;
                 }
                 if (!is_null($constant_value = WPLib::get_constant($constant_name, $class_name))) {
                     continue;
                 }
                 $child_classes[$constant_value] = $class_name;
             } while (false);
         }
         WPLib::cache_set($cache_key, $child_classes);
     }
     return $child_classes;
 }
Beispiel #6
0
 /**
  * Returns a file hash, but caches it in persistent cache
  *
  * @param string $filepath
  *
  * @return string
  */
 static function file_hash($filepath)
 {
     $subscript = self::is_development() ? $filepath : md5($filepath);
     if ($file_hash = WPLib::cache_get($cache_key = "file_hash[{$subscript}]")) {
         WPLib::cache_get($cache_key, md5_file($filepath));
     }
     return $file_hash;
 }
 /**
  * @return string
  */
 static function post_type_list_class()
 {
     $called_class = get_called_class();
     if (!($post_type_list_class = WPLib::cache_get($cache_key = "list_post_type_class[{$called_class}]"))) {
         foreach (WPLib::site_classes() as $class_name) {
             if (is_subclass_of($class_name, 'WPLib_Post_List_Base') && ($post_type = static::get_constant('POST_TYPE', $class_name))) {
                 $post_type_list_class = $class_name;
             }
         }
         if (!$post_type_list_class) {
             $post_type_list_class = 'WPLib_Post_List_Default';
         }
         WPLib::cache_get($cache_key, $post_type_list_class);
     }
     return $post_type_list_class;
 }