mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #4438 from kinglozzer/pulls/deprecate-object-caching
Mark Object caching methods as deprecated
This commit is contained in:
commit
afe9cc68a4
@ -995,6 +995,8 @@ abstract class Object {
|
|||||||
* @return mixed the cached data
|
* @return mixed the cached data
|
||||||
*/
|
*/
|
||||||
public function cacheToFile($method, $lifetime = 3600, $ID = false, $arguments = array()) {
|
public function cacheToFile($method, $lifetime = 3600, $ID = false, $arguments = array()) {
|
||||||
|
Deprecation::notice('4.0', 'Caching methods on Object have been deprecated. Use the SS_Cache API instead.');
|
||||||
|
|
||||||
if(!$this->hasMethod($method)) {
|
if(!$this->hasMethod($method)) {
|
||||||
throw new InvalidArgumentException("Object->cacheToFile(): the method $method does not exist to cache");
|
throw new InvalidArgumentException("Object->cacheToFile(): the method $method does not exist to cache");
|
||||||
}
|
}
|
||||||
@ -1022,6 +1024,8 @@ abstract class Object {
|
|||||||
* Clears the cache for the given cacheToFile call
|
* Clears the cache for the given cacheToFile call
|
||||||
*/
|
*/
|
||||||
public function clearCache($method, $ID = false, $arguments = array()) {
|
public function clearCache($method, $ID = false, $arguments = array()) {
|
||||||
|
Deprecation::notice('4.0', 'Caching methods on Object have been deprecated. Use the SS_Cache API instead.');
|
||||||
|
|
||||||
$cacheName = $this->class . '_' . $method;
|
$cacheName = $this->class . '_' . $method;
|
||||||
if(!is_array($arguments)) $arguments = array($arguments);
|
if(!is_array($arguments)) $arguments = array($arguments);
|
||||||
if($ID) $cacheName .= '_' . $ID;
|
if($ID) $cacheName .= '_' . $ID;
|
||||||
@ -1039,6 +1043,8 @@ abstract class Object {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function loadCache($cache, $lifetime = 3600) {
|
protected function loadCache($cache, $lifetime = 3600) {
|
||||||
|
Deprecation::notice('4.0', 'Caching methods on Object have been deprecated. Use the SS_Cache API instead.');
|
||||||
|
|
||||||
$path = TEMP_FOLDER . '/' . $this->sanitiseCachename($cache);
|
$path = TEMP_FOLDER . '/' . $this->sanitiseCachename($cache);
|
||||||
|
|
||||||
if(!isset($_REQUEST['flush']) && file_exists($path) && (filemtime($path) + $lifetime) > time()) {
|
if(!isset($_REQUEST['flush']) && file_exists($path) && (filemtime($path) + $lifetime) > time()) {
|
||||||
@ -1055,6 +1061,7 @@ abstract class Object {
|
|||||||
* @param mixed $data data to save (must be serializable)
|
* @param mixed $data data to save (must be serializable)
|
||||||
*/
|
*/
|
||||||
protected function saveCache($cache, $data) {
|
protected function saveCache($cache, $data) {
|
||||||
|
Deprecation::notice('4.0', 'Caching methods on Object have been deprecated. Use the SS_Cache API instead.');
|
||||||
file_put_contents(TEMP_FOLDER . '/' . $this->sanitiseCachename($cache), serialize($data));
|
file_put_contents(TEMP_FOLDER . '/' . $this->sanitiseCachename($cache), serialize($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1065,6 +1072,7 @@ abstract class Object {
|
|||||||
* @return string the name with all special cahracters replaced with underscores
|
* @return string the name with all special cahracters replaced with underscores
|
||||||
*/
|
*/
|
||||||
protected function sanitiseCachename($name) {
|
protected function sanitiseCachename($name) {
|
||||||
|
Deprecation::notice('4.0', 'Caching methods on Object have been deprecated. Use the SS_Cache API instead.');
|
||||||
return str_replace(array('~', '.', '/', '!', ' ', "\n", "\r", "\t", '\\', ':', '"', '\'', ';'), '_', $name);
|
return str_replace(array('~', '.', '/', '!', ' ', "\n", "\r", "\t", '\\', ':', '"', '\'', ';'), '_', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user