Caching the Data using APC – Alternative PHP Cache

Now a days most of the website are used to cache their data to reduce the server load, Also speed up the response. We are going to discuss about the APC – Alternative PHP Cache.

APC is a Alternative PHP Cache as I already mentioned, its used to cache the data, remove and expire in the given time.  To work with APC first we need to enable php_apc.dll in windows and in Linux operating system.

Where to use APC ?

Consider you have a website with lots of content driven from database with data for all the users, on that time you cannot query the database each and every time. To avoid this case we will cache the data and share between the users. This will allow one time query and share the same data between the users.

Let’s see about fews function in APC.

apc_add – function used to store a data in key format and expire it in given TTL.

apc_add ( array $values [, mixed $unused = NULL [, int $ttl = 0 ]] )

Assigning value into $myData variable

    $myData = 'Welcome to APC';

apc_fetch – function used to fetch data from the given key.

apc_fetch ( mixed $key [, bool &$success ] )

fetching value from the key myData.

echo apc_fetch('myData');

apc_delete – function remove the data from the cache.

apc_delete ( string $key )

Removing the data from the key.