@@ -325,23 +325,22 @@ public function element($name, $params = array(), $callbacks = false) {
325
325
}
326
326
327
327
if (isset ($ params ['cache ' ])) {
328
- $ expires = '+1 day ' ;
329
-
330
328
if (is_array ($ params ['cache ' ])) {
331
- $ expires = $ params ['cache ' ]['time ' ];
332
- $ key = Inflector::slug ($ params ['cache ' ]['key ' ]);
333
- } elseif ($ params ['cache ' ] !== true ) {
334
- $ expires = $ params ['cache ' ];
335
- $ key = implode ('_ ' , array_keys ($ params ));
329
+ $ defaults = array (
330
+ 'config ' => 'default ' ,
331
+ 'key ' => '' ,
332
+ );
333
+ $ caching = array_merge ($ defaults , $ params ['cache ' ]);
334
+ } else {
335
+ $ caching = array (
336
+ 'config ' => 'default ' ,
337
+ 'key ' => implode ('_ ' , array_keys ($ params ))
338
+ );
336
339
}
337
-
338
- if ($ expires ) {
339
- $ cacheFile = 'element_ ' . $ key . '_ ' . $ plugin . Inflector::slug ($ name );
340
- $ cache = cache ('views ' . DS . $ cacheFile , null , $ expires );
341
-
342
- if (is_string ($ cache )) {
343
- return $ cache ;
344
- }
340
+ $ key = 'element_ ' . $ caching ['key ' ] . '_ ' . $ plugin . Inflector::slug ($ name );
341
+ $ contents = Cache::read ($ key , $ caching ['config ' ]);
342
+ if ($ contents !== false ) {
343
+ return $ contents ;
345
344
}
346
345
}
347
346
$ paths = $ this ->_paths ($ plugin );
@@ -364,8 +363,8 @@ public function element($name, $params = array(), $callbacks = false) {
364
363
if ($ callbacks ) {
365
364
$ this ->Helpers ->trigger ('afterRender ' , array ($ file , $ element ));
366
365
}
367
- if (isset ($ params ['cache ' ]) && isset ( $ cacheFile ) && isset ( $ expires ) ) {
368
- cache ( ' views ' . DS . $ cacheFile , $ element , $ expires );
366
+ if (isset ($ params ['cache ' ])) {
367
+ Cache:: write ( $ key , $ element , $ caching [ ' config ' ] );
369
368
}
370
369
return $ element ;
371
370
}
0 commit comments