blueshoes php application framework and cms            core_file
[ class tree: core_file ] [ index: core_file ] [ all elements ]

example


1 <?php
2 # example 2:
3 # Use with some property settings.
4 # This time there is no 'origin-file' file and we use a 'lifetime'
5 # for the cache.
6
7
8 #include dependencies
9 require_once($_SERVER["DOCUMENT_ROOT"] . "../global.conf.php");
10 include_once($APP['path']['core'] . 'file/Bs_FileCache.class.php');
11
12 # 1) create the instance and set properties
13 $cacher =& new Bs_FileCache();
14 $cacher->setDir('r:/'); // hint: Use a RAM-Disk! hint 2: use getTmp() it returns the temp folder of your operating system.
15 $cacher->setBufferSize('200k'); // % of memory is also possible
16 $cacher->setVerboseCacheNames(TRUE); // Give cache-files a readable name
17
18 # 2) Try to get the cached data using any key *you* define.
19 $MY_CACHE_KEY = 'chacheKey_1';
20 $data = $cacher->fetch($MY_CACHE_KEY);
21
22 # 3) Test the return value
23 if ($data === FALSE) { // ERROR
24 echo "ERROR: " . $cacher->getLastError();
25 } elseif ($data === NULL){ // cache is "Out Of Date", or not cached yet.
26 // Crunch the data (Replaced with *YOUR* crunching function.)
27 $crunchedData = myCruncher('/tmp/toCrunchData.txt');
28 # 4) Cache the data serialized with a timeout of 600s
29 # and disabled 'origin-file' check
30 $cacher->store($MY_CACHE_KEY, serialize($crunchedData), $originCheck=FALSE, 600);
31 } else { // SUCCESS
32 $crunchedData = unserialize($data);
33 }
34
35 # 5) do something with $crunchedData
36 dump($crunchedData);
37
38
39 # this is your cruncher function. of course you would do more
40 # than just reading the data.
41 function myCruncher($fullPath) {
42 return join('', file($fullPath));
43 }
44 ?>

Documentation generated on Mon, 29 Dec 2003 21:09:03 +0100 by phpDocumentor 1.2.3