-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_model.php
executable file
·62 lines (50 loc) · 1.27 KB
/
app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
/**
* Application model for Cake.
*
* This file is application-wide model file. You can put all
* application-wide model-related methods here.
*
*/
/**
* Application model for Cake.
*
* This is a placeholder class.
* Create the same file in app/app_model.php
* Add your application-wide methods to the class, your models will inherit them.
*
*/
class AppModel extends Model {
function nativeQuery($query,$Cache= false,$QryKey=null,$QryExpires=null){
if(isset($query) && !empty($query) && is_string($query)){
if($Cache != false && isset($QryKey) && !is_null($QryKey)){
$key = $QryKey;
$expires = '+1 hour';
if (isset($QryExpires) && !is_null($QryExpires) ) {
$expires=$QryExpires;
}
// cache settings
Cache::config('sql_cache', array(
'prefix' => strtolower($this->name) .'-',
'duration' => $expires
));
// read result from cache
$results = Cache::read($key, 'sql_cache');
if (!is_array($results)) {
$results = $this->query($query);
Cache::write($key, $results, 'sql_cache');
}
return $results;
}else{
//NON-CHACHED QUERY
$result=$this->query($query);
return $result;
}
}else{
// no query available
return false;
}
}
}
?>