-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryCacheBuilder.php
More file actions
93 lines (80 loc) · 1.9 KB
/
QueryCacheBuilder.php
File metadata and controls
93 lines (80 loc) · 1.9 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
<?php
namespace SimpleSoftwareIO\Cache;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Processors\Processor;
class QueryCacheBuilder extends Builder
{
/**
* Holds the QueryCache instance.
*
* @var QueryCache
*/
protected $cache;
/**
* QueryCacheBuilder constructor.
*
* @param QueryCache $cache
* @param ConnectionInterface $connection
* @param Grammar $grammar
* @param Processor $processor
*/
public function __construct(QueryCache $cache, ConnectionInterface $connection, Grammar $grammar, Processor $processor)
{
$this->cache = $cache;
parent::__construct($connection, $grammar, $processor);
}
/**
* Generates a new query.
*
* @return static
*/
public function newQuery()
{
return new static($this->cache, $this->connection, $this->grammar, $this->processor);
}
/**
* Returns the query results.
*
* @param array $columns
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function get($columns = ['*'])
{
return $this->cache->get($this, $columns);
}
/**
* Sets the time to remember a query.
*
* @param int $minutes
*
* @return $this
*/
public function remember($minutes)
{
$this->cache->length($minutes);
return $this;
}
/**
* Remembers a query forever (10 years).
*
* @return $this
*/
public function rememberForever()
{
$this->cache->length(60 * 24 * 365 * 10);
return $this;
}
/**
* Turns off query caching.
*
* @return $this
*/
public function dontRemember()
{
$this->cache->disable();
return $this;
}
}