Cachearium\CacheAbstract::getDataP PHP Method

getDataP() public method

Same as getData(), but expanded parameters.
See also: getData()
public getDataP ( string $base, string $id, mixed $sub = null )
$base string
$id string
$sub mixed
    public function getDataP($base, $id, $sub = null)
    {
        return $this->getData(new CacheKey($base, $id, $sub));
    }

Usage Example

 private function getStoreData(CacheAbstract $cache)
 {
     $base = 'base';
     $this->assertTrue($cache->isEnabled());
     $cache->setDefaultLifetime(3600);
     $this->assertEquals(3600, $cache->getDefaultLifetime());
     // clean
     $key1 = new CacheKey($base, 1);
     $cache->clean($key1);
     // nothing there
     try {
         $data = $cache->get($key1);
         $this->fail();
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
     // store
     $cd = new CacheData($key1, 234);
     $retval = $cache->storeData($cd);
     $this->assertTrue($retval);
     // get
     try {
         $data = $cache->getData($key1);
         $this->assertInstanceOf('Cachearium\\CacheData', $data);
         $this->assertEquals(234, $data->getFirstData());
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->fail();
     }
     // ivalid
     try {
         $data2 = $cache->getDataP("some", "random", "stuff");
         $this->fail();
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
     sleep(1);
     try {
         $data = $cache->getData($key1);
         $this->assertInstanceOf('Cachearium\\CacheData', $data);
         $this->assertEquals(234, $data->getFirstData());
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->fail();
     }
     // clean
     $cache->clean($key1);
     try {
         $data = $cache->getData($key1);
         $this->fail();
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
     // check conflicts
     $key2 = new CacheKey($base, 2, 'a');
     $key3 = new CacheKey($base, 3, 'a');
     // now change again and delete
     $retval = $cache->storeData(new CacheData($key2, 234));
     $this->assertEquals(true, $retval);
     try {
         $data = $cache->getData($key2);
         $this->assertInstanceOf('Cachearium\\CacheData', $data);
         $this->assertEquals(234, $data->getFirstData());
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->fail();
     }
     $this->assertTrue($cache->delete($key2));
     // test null
     $retval = $cache->storeData(new CacheData($key3), null);
     $this->assertEquals(true, $retval);
     try {
         $data = $cache->getData($key3);
         $this->assertInstanceOf('Cachearium\\CacheData', $data);
         $this->assertEquals(null, $data->getFirstData());
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->fail();
     }
     $this->assertTrue($cache->delete($key3));
 }