@@ -37,6 +37,7 @@ class SelectStatement extends Select {
37
37
private $ adapter = null ;
38
38
39
39
private static $ logger = null ;
40
+ private static $ isCaching = null ;
40
41
41
42
/**
42
43
* Get the SelectStatement instance with the given id.
@@ -46,18 +47,17 @@ class SelectStatement extends Select {
46
47
* @return SelectStatement
47
48
*/
48
49
public static function get (RDBMapper $ mapper , $ id =self ::NO_CACHE ) {
49
- $ cache = ObjectFactory::getInstance ('staticCache ' );
50
- $ cacheSection = self ::getCacheSection ($ mapper ->getType ());
51
- $ cacheId = self ::getCacheId ($ id );
52
- if ($ id == self ::NO_CACHE || !$ cache ->exists ($ cacheSection , $ cacheId )) {
50
+ $ isCaching = self ::isCaching () && $ id !== self ::NO_CACHE ;
51
+ if ($ isCaching ) {
52
+ $ cache = ObjectFactory::getInstance ('staticCache ' );
53
+ $ cacheSection = self ::getCacheSection ($ mapper ->getType ());
54
+ $ cacheId = self ::getCacheId ($ id );
55
+ }
56
+ if (!$ isCaching || !$ cache ->exists ($ cacheSection , $ cacheId )) {
53
57
$ selectStmt = new SelectStatement ($ mapper , $ id );
54
58
}
55
59
else {
56
60
$ selectStmt = $ cache ->get ($ cacheSection , $ cacheId );
57
- if (!$ selectStmt ) {
58
- $ cache ->remove ($ cacheSection , $ cacheId );
59
- $ selectStmt = new SelectStatement ($ mapper , $ id );
60
- }
61
61
$ selectStmt ->adapter = $ mapper ->getAdapter ();
62
62
}
63
63
return $ selectStmt ;
@@ -108,7 +108,7 @@ public function getType() {
108
108
*/
109
109
public function isCached () {
110
110
$ cache = ObjectFactory::getInstance ('staticCache ' );
111
- return $ this ->id == self ::NO_CACHE ? false :
111
+ return (! self :: isCaching () || $ this ->id == self ::NO_CACHE ) ? false :
112
112
$ cache ->exists (self ::getCacheSection ($ this ->type ), self ::getCacheId ($ this ->id ));
113
113
}
114
114
@@ -209,7 +209,7 @@ public function getRowCount() {
209
209
* Put the statement into the cache
210
210
*/
211
211
public function save () {
212
- if ($ this ->id != self ::NO_CACHE ) {
212
+ if (self :: isCaching () && $ this ->id != self ::NO_CACHE ) {
213
213
$ cache = ObjectFactory::getInstance ('staticCache ' );
214
214
$ cache ->put (self ::getCacheSection ($ this ->type ), self ::getCacheId ($ this ->id ), $ this );
215
215
}
@@ -315,13 +315,25 @@ protected function getAdapter() {
315
315
return $ this ->adapter ;
316
316
}
317
317
318
+ /**
319
+ * Check if statements are cached
320
+ * @return Boolean
321
+ */
322
+ protected static function isCaching () {
323
+ if (self ::$ isCaching == null ) {
324
+ $ configuration = ObjectFactory::getInstance ('configuration ' );
325
+ self ::$ isCaching = !$ configuration ->hasValue ('statementCaching ' , 'persistenceFacade ' ) || $ configuration ->getBooleanValue ('statementCaching ' , 'persistenceFacade ' ) === true ;
326
+ }
327
+ return self ::$ isCaching ;
328
+ }
329
+
318
330
/**
319
331
* Get the cache section
320
332
* @param $type The type
321
333
* @return String
322
334
*/
323
335
protected static function getCacheSection ($ type ) {
324
- return self ::CACHE_KEY .'/ ' .$ type ;
336
+ return self ::CACHE_KEY .'. ' .$ type ;
325
337
}
326
338
327
339
/**
0 commit comments