class-wpml-wp-cache.php 698 Bytes
Newer Older
John Punzalan's avatar
John Punzalan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php

class WPML_WP_Cache {

	private $group;
	
	public function __construct( $group = '' ) {
		$this->group = $group;
	}
	
	public function get( $key, &$found ) {
		$value = wp_cache_get( $key, $this->group );
		if ( is_array( $value) && array_key_exists( 'data', $value ) ) {
			// we know that we have set something in the cache.
			$found = true;
			return $value[ 'data' ];
		} else {
			$found = false;
			return $value;
		}
	}
	
	public function set( $key, $value, $expire = 0 ) {
		
		// Save $value in an array. We need to do this because W3TC 0.9.4.1 doesn't
		// set the $found value when fetching data.
		
		wp_cache_set( $key, array( 'data' => $value ), $this->group, $expire );
	}
}