-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheable.php
More file actions
123 lines (106 loc) · 2.34 KB
/
Copy pathCacheable.php
File metadata and controls
123 lines (106 loc) · 2.34 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace SimpleSoftwareIO\Cache;
trait Cacheable
{
/**
* Returns the Cache store to use.
*
* @return null|string
*/
public function getCacheStore()
{
if (isset($this->cacheStore)) {
return $this->cacheStore;
}
}
/**
* Returns if the cache should be busted
* on inserts/updates/delete.
*
* @return bool
*/
public function getCacheBusting()
{
if (isset($this->cacheBusting)) {
return $this->cacheBusting;
}
return false;
}
/**
* Gets the length of the cache. Defaults to 30 minutes.
*
* @return int
*/
public function getCacheLength()
{
if (isset($this->cacheLength)) {
return $this->cacheLength * 60;
}
return 30 * 60;
}
/**
* Overrides the default QueryBuilder to inject the Cache methods.
*
* @return QueryCacheBuilder
*/
protected function newBaseQueryBuilder()
{
$conn = $this->getConnection();
$grammar = $conn->getQueryGrammar();
return new QueryCacheBuilder($this->queryCache(), $conn, $grammar, $conn->getPostProcessor());
}
/**
* Generates a new QueryCache.
*
* @return QueryCache
*/
protected function queryCache()
{
return new QueryCache($this->getCacheStore(), $this->getCacheLength());
}
/**
* Flushes the cache on insert/update.
*
* @param array $options
*
* @return void
*/
public function finishSave(array $options)
{
if ($this->getCacheBusting()) {
$this->queryCache()->flush($this->getTable());
}
parent::finishSave($options);
}
/**
* Flushes the cache on deletes.
*
* @return bool|null
*/
public function delete()
{
if ($this->getCacheBusting()) {
$this->queryCache()->flush($this->getTable());
}
return parent::delete();
}
/**
* Returns the status of cache busting.
*
* @return bool
*/
public function isBusting()
{
return $this->getCacheBusting();
}
/**
* Flushes the cache.
*
* @return $this
*/
public function flush()
{
$this->queryCache()->flush($this->getTable());
return $this;
}
}