PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.14.1
Last Build: March 10, 2017 13:28pm (PST)

psCacheWrite()
Caches data to a file


Description:

These functions are used to cache data to a file
I use this when calling another function takes a long time, and has to parse
a lot of data, that seldom changes

Cache time is on the read function, this allow cache time changes without affecting
files already written.



Usage:


psCacheWrite($mixed,$cFile)
$mixed = single var, or an array: is $mixed = 1 or $mixed[0] = 1
$cFile = Name of file to save, ex: /tmp/data.cache



Example:

	$wFile = "test.cache";
$ary = psCacheRead($wFile);

if ($ary == false)
{
print"* Cache Expired\r\n";

$d['gallardo'] = "green";
$d['yellow'] = "yellow";

psCacheWrite($d,$wFile,20);
}




Code:



function psCacheWrite($mixed,$cFile)
{
//print"* psCacheWrite()\r\n";
$cache['ts'] = time();
$cache['data'] = $mixed;
file_put_contents($cFile,serialize($cache));
}

Changlelog:


See Also

  psCacheRead()
  psCacheWrite()
And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site