| 1 |
<?php |
| 2 |
|
| 3 |
namespace FL\Assistant\System\Container; |
| 4 |
|
| 5 |
class ReflectionCacheApc implements ReflectionCache { |
| 6 |
|
| 7 |
private $localCache; |
| 8 |
private $timeToLive = 5; |
| 9 |
|
| 10 |
public function __construct( ReflectionCache $localCache = null ) { |
| 11 |
$this->localCache = $localCache ?: new ReflectionCacheArray; |
| 12 |
} |
| 13 |
|
| 14 |
public function setTimeToLive( $seconds ) { |
| 15 |
$seconds = (int) $seconds; |
| 16 |
$this->timeToLive = ( $seconds > 0 ) ? $seconds : $this->timeToLive; |
| 17 |
|
| 18 |
return $this; |
| 19 |
} |
| 20 |
|
| 21 |
public function fetch( $key ) { |
| 22 |
$localData = $this->localCache->fetch( $key ); |
| 23 |
|
| 24 |
if ( $localData != false ) { |
| 25 |
return $localData; |
| 26 |
} else { |
| 27 |
$success = null; // stupid by-ref parameter that scrutinizer complains about |
| 28 |
$data = apc_fetch( $key, $success ); |
| 29 |
return $success ? $data : false; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
public function store( $key, $data ) { |
| 34 |
$this->localCache->store( $key, $data ); |
| 35 |
apc_store( $key, $data, $this->timeToLive ); |
| 36 |
} |
| 37 |
} |
| 38 |
|