Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Very simple filesystem cache
4
 *
5
 * $Id: Filesystem.php,v 1.1 2005/01/04 22:38:23 schst Exp $
6
 *
7
 * @package Services_Ebay
8
 * @author  Stephan Schmidt <schst@php.net>
9
 */
10
 
11
/**
12
 * load base class for caches
13
 */
14
require_once SERVICES_EBAY_BASEDIR . '/Ebay/Cache.php';
15
 
16
/**
17
 * Very simple filesystem cache
18
 *
19
 * $Id: Filesystem.php,v 1.1 2005/01/04 22:38:23 schst Exp $
20
 *
21
 * @package Services_Ebay
22
 * @author  Stephan Schmidt <schst@php.net>
23
 *
24
 * @todo    add some checks before writing files
25
 */
26
class Services_Ebay_Cache_Filesystem extends Services_Ebay_Cache
27
{
28
   /**
29
    * load a model from cache
30
    *
31
    * @param    string      model type
32
    * @param    string      primary key
33
    * @param    integer     detail level
34
    * @return   array|boolean
35
    */
36
    public function load($Type, $Key, $DetailLevel)
37
    {
38
        $filename = $this->getCacheFilename($Type, $Key, $DetailLevel);
39
        if (!file_exists($filename)) {
40
        	return false;
41
        }
42
        if (!is_readable($filename)) {
43
        	return false;
44
        }
45
 
46
        // time the cache has been created
47
        $created = filemtime($filename);
48
        $props   = unserialize(file_get_contents($filename));
49
 
50
        // check validity
51
        if (!$this->isValid($Type, $created, $props)) {
52
        	return false;
53
        }
54
 
55
        // return the cache
56
        return $props;
57
    }
58
 
59
   /**
60
    * store model data in the cache
61
    *
62
    * @param    string      model type
63
    * @param    string      primary key
64
    * @param    integer     detail level
65
    * @param    array       properties
66
    * @return   boolean
67
    */
68
    public function store($Type, $Key, $DetailLevel, $Props)
69
    {
70
        $filename = $this->getCacheFilename($Type, $Key, $DetailLevel);
71
    	return file_put_contents($filename, serialize($Props));
72
    }
73
 
74
   /**
75
    * get the name of the cache file
76
    *
77
    * @param    string      model type
78
    * @param    string      primary key
79
    * @param    integer     detail level
80
    * @return   string
81
    */
82
    private function getCacheFilename($Type, $Key, $DetailLevel)
83
    {
84
        return sprintf('%s/%s_%s_%s.cache',$this->options['path'], $Type, md5($Key), $DetailLevel);
85
    }
86
}
87
?>