WP_CLI
FileCache::has()
Check if a file is in cache and return its filename
Method of the class: FileCache{}
No Hooks.
Return
true|false|String
. filename or false
Usage
$FileCache = new FileCache(); $FileCache->has( $key, $ttl );
- $key(string) (required)
- cache key
- $ttl(int)
- time to live
Default: null
FileCache::has() FileCache::has code WP-CLI 2.8.0-alpha
public function has( $key, $ttl = null ) { if ( ! $this->enabled ) { return false; } $filename = $this->filename( $key ); if ( ! file_exists( $filename ) ) { return false; } // Use ttl param or global ttl. if ( null === $ttl ) { $ttl = $this->ttl; } elseif ( $this->ttl > 0 ) { $ttl = min( (int) $ttl, $this->ttl ); } else { $ttl = (int) $ttl; } // if ( $ttl > 0 && ( filemtime( $filename ) + $ttl ) < time() ) { if ( $this->ttl > 0 && $ttl >= $this->ttl ) { unlink( $filename ); } return false; } return $filename; }