# assistant/0.3.1/backend/src/System/Container/ReflectionCacheApc.php

Assistant – Every Day Productivity Apps, version 0.3.1. 38 lines.

- Page: https://pluginprobe.com/plugins/assistant/0.3.1/code/backend/src/System/Container/ReflectionCacheApc.php
- Raw: https://pluginprobe.com/plugins/assistant/0.3.1/raw/backend/src/System/Container/ReflectionCacheApc.php
- Modified: 2020-03-25T19:33:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/assistant/0.3.1/code/backend/src/System/Container/ReflectionCacheApc.php#L10-L20`.

```php
<?php

namespace FL\Assistant\System\Container;

class ReflectionCacheApc implements ReflectionCache {

	private $localCache;
	private $timeToLive = 5;

	public function __construct( ReflectionCache $localCache = null ) {
		$this->localCache = $localCache ?: new ReflectionCacheArray;
	}

	public function setTimeToLive( $seconds ) {
		$seconds = (int) $seconds;
		$this->timeToLive = ( $seconds > 0 ) ? $seconds : $this->timeToLive;

		return $this;
	}

	public function fetch( $key ) {
		$localData = $this->localCache->fetch( $key );

		if ( $localData != false ) {
			return $localData;
		} else {
			$success = null; // stupid by-ref parameter that scrutinizer complains about
			$data = apc_fetch( $key, $success );
			return $success ? $data : false;
		}
	}

	public function store( $key, $data ) {
		$this->localCache->store( $key, $data );
		apc_store( $key, $data, $this->timeToLive );
	}
}

```
