2017 © Pedro Peláez
 

library apc

Simple wrapper for some APC features.

image

malenki/apc

Simple wrapper for some APC features.

  • Saturday, April 26, 2014
  • by malenki
  • Repository
  • 3 Watchers
  • 5 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Apc

Small wrapper of some apc features., (*1)

Install

You can clone this repository or use composer, because APC is available on Packagist!, (*2)

{
    "require": {
        "malenki/apc": "dev-master",
    }
}

Instanciate

While you instanciate an object of this class, you must give at least one argument to set the key name:, (*3)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected'); // TTL = 0 by default here

You can give second argument, an positive integer, for the time to live duration in seconds:, (*4)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 60); // Given TTL is one minute

Setting value

Very easy, you have the choice by using set() method or the magick setter value:, (*5)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 3600);
$apc->set('foo');
//or
$apc->value = 'foo';

Getting value

As you have seen into previous case, you can use for getting value two ways: get() method or magic getter value., (*6)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 3600);
var_dump($apc->get());
//or
var_dump($apc->value);

You may print content into string context too:, (*7)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 3600);
$apc->value = 'foo';
echo $apc; // will print "foo"

If the value is not a scalar, print_r() function is used., (*8)

Deleting value

You can force removing value from APC cache using delete() method or magic unset():, (*9)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 3600);
$apc->set('foo');
$apc->delete();
// or
unset($apc->value);

Testing value

You can test if a value exists before doing something with it. You have to call exists() method or magic isset():, (*10)

use \Malenki\Apc;
$apc = new Apc('key_id_you_have_selected', 3600);

// using method
if(!$apc->exists())
{
    $apc->value = 'foo';
}

// or magic isset()
if(!isset($apc->value))
{
    $apc->value = 'foo';
}

Cleaning the cache

You can clean all or just some part like user or opcode:, (*11)

use \Malenki\Apc;
Apc::clean(); // clean all
// or
Apc::clean('user'); // clean user cache type
// or
Apc::clean('opcode'); // clean opcode cache type

The Versions

26/04 2014

dev-master

9999999-dev https://github.com/malenkiki/apc

Simple wrapper for some APC features.

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-apc *

 

cache apc oop