malenki / apc
Simple wrapper for some APC features.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/malenki/apc
Requires
- php: >=5.3.0
- ext-apc: *
This package is not auto-updated.
Last update: 2025-10-11 20:31:45 UTC
README
Small wrapper of some apc features.
Install
You can clone this repository or use composer, because APC is available on Packagist!
{
"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:
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:
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:
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.
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:
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.
Deleting value
You can force removing value from APC cache using delete() method or magic unset():
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():
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:
use \Malenki\Apc; Apc::clean(); // clean all // or Apc::clean('user'); // clean user cache type // or Apc::clean('opcode'); // clean opcode cache type