Undefined cache functions in my custom plugin

Question

I am making a plugin that make a HTTP call to my API, I want this call be cached an tried using this way:

static function get_info(){
    $cache = wp_cache_get( $username, "action" );
    if(!cache){
        $cache = file_get_contents(...);
        wp_cache_set( $username, $cache, "action", 900 );
    }
    return $cache;
}

When I run this code (this php file are inside my plugin) I am getting

“Fatal error: Uncaught Error: Call to undefined function
wp_cache_get()”

I have to maque a require from wp-includes.php cache file? Or maybe I am missing something.

0
user1422434 4 months 0 Answers 14 views 0

Leave an answer