|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class OneCallObjectCacher extends Object |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* |
|
9
|
|
|
* @var array |
|
10
|
|
|
*/ |
|
11
|
|
|
private static $_object_store = array(); |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
private static $_reference_to_full_key = array(); |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
public static function get_one($callerClass, $filter = "", $cache = true, $orderby = "") |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private static $_list_cache = array(); |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public static function clear_all() |
|
32
|
|
|
{ |
|
33
|
|
|
self::$_object_store = array(); |
|
34
|
|
|
self::$_reference_to_full_key = array(); |
|
35
|
|
|
self::$_list_cache = array(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public static function clear_objects() |
|
40
|
|
|
{ |
|
41
|
|
|
self::$_object_store = array(); |
|
42
|
|
|
self::$_reference_to_full_key = array(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public static function clear_lists() |
|
46
|
|
|
{ |
|
47
|
|
|
self::$_list_cache = array(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* stores any dataobject |
|
53
|
|
|
* @param DataObject |
|
54
|
|
|
* |
|
55
|
|
|
* @return DataObject |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function store_object($object, $key = null) |
|
58
|
|
|
{ |
|
59
|
|
|
$originalKey = $key; |
|
60
|
|
|
$key .= '_'.$object->ClassName.'_'.$object->ID; |
|
61
|
|
|
self::$_reference_to_full_key[$originalKey] = $key; |
|
62
|
|
|
self::$_object_store[$key] = $object; |
|
63
|
|
|
|
|
64
|
|
|
return $object; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* stores any dataobject |
|
69
|
|
|
* @param string $key |
|
70
|
|
|
* @param string $className (optional) |
|
71
|
|
|
* @param int $id (optional) |
|
72
|
|
|
* |
|
73
|
|
|
* @return DataObject |
|
74
|
|
|
*/ |
|
75
|
|
|
public static function retrieve_object($key, $className = '', $id = 0) |
|
76
|
|
|
{ |
|
77
|
|
|
$originalKey = $key; |
|
78
|
|
|
$key .= '_'.$className.'_'.$id; |
|
79
|
|
|
if (isset(self::$_object_store[$key])) { |
|
80
|
|
|
} else { |
|
81
|
|
|
if (isset(self::$_object_store[self::$_reference_to_full_key[$originalKey]])) { |
|
82
|
|
|
return self::$_object_store[self::$_reference_to_full_key[$originalKey]]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $object; |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* clears all the references to one object... |
|
91
|
|
|
* returns true if found and false it not found ... |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $className |
|
94
|
|
|
* @param int $id |
|
95
|
|
|
* |
|
96
|
|
|
* @return bool |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function clear_one_object($className, $id) |
|
99
|
|
|
{ |
|
100
|
|
|
$keyEnd = '_'.$className.'_'.$id; |
|
101
|
|
|
$keyEndLength = strlen($keyEnd); |
|
102
|
|
|
foreach (self::$_object_store as $key => $ignore) { |
|
103
|
|
|
if (substr($key, -$keyEndLength) === $keyEnd) { |
|
104
|
|
|
$referenceKey = subst($key, 0, strlen($key) - $keyEndLength); |
|
105
|
|
|
unset(self::$_object_store[$key]); |
|
106
|
|
|
unset(self::$_reference_to_full_key[$referenceKey]); |
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* return a data list |
|
116
|
|
|
* @param SS_List |
|
117
|
|
|
* @param string $key |
|
118
|
|
|
* |
|
119
|
|
|
* @return SS_List |
|
120
|
|
|
*/ |
|
121
|
|
|
public static function store_list($dataList, $key) |
|
122
|
|
|
{ |
|
123
|
|
|
self::$_list_cache[$key] = $dataList->column('ID'); |
|
124
|
|
|
|
|
125
|
|
|
return $dataList; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $key |
|
131
|
|
|
* |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
|
public static function retrieve_list($key) |
|
135
|
|
|
{ |
|
136
|
|
|
return self::$_list_cache[$key]; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.