Skip to content

Commit 9bf7e92

Browse files
author
Corey McCormick
committed
Drop bust and dontBust in favor for flush
1 parent 38571b5 commit 9bf7e92

File tree

3 files changed

+30
-52
lines changed

3 files changed

+30
-52
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,11 @@ Cache busting will automatically invalid the cache when an `insert/update/delete
103103
104104
### Methods
105105

106-
#### bust()
106+
#### flush()
107107

108-
The `bust` method will enable cache busting for the model
108+
The `flush` method will flush the cache for a model.
109109

110-
User::bust(); //Cache busting is enabled.
111-
112-
#### dontBust()
113-
114-
The `dontBust` method will disable cache busting for the model.
115-
116-
User::dontBust(); //Cache busting is disabled.
110+
User::flush(); //Cache is flushed for the `User` model.
117111

118112
#### isBusting()
119113

src/Cacheable.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,36 +99,24 @@ public function delete()
9999
}
100100

101101
/**
102-
* Enables cache busting.
102+
* Returns the status of cache busting.
103103
*
104-
* @return Cacheable
104+
* @return bool
105105
*/
106-
public function bust()
106+
public function isBusting()
107107
{
108-
$this->cacheBusting = true;
109-
110-
return $this;
108+
return $this->getCacheBusting();
111109
}
112110

113111
/**
114-
* Disables cache busting.
112+
* Flushes the cache.
115113
*
116-
* @return Cacheable
114+
* @return $this
117115
*/
118-
public function dontBust()
116+
public function flush()
119117
{
120-
$this->cacheBusting = false;
118+
$this->queryCache()->flush($this->getTable());
121119

122120
return $this;
123121
}
124-
125-
/**
126-
* Returns the status of cache busting.
127-
*
128-
* @return bool
129-
*/
130-
public function isBusting()
131-
{
132-
return $this->getCacheBusting();
133-
}
134122
}

tests/CacheableTest.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class Model extends EloquentModel
99
use Cacheable;
1010
}
1111

12+
class BustingModel extends EloquentModel
13+
{
14+
use Cacheable;
15+
16+
protected $cacheBusting = true;
17+
}
18+
1219
class CacheableTest extends PHPUnit_Framework_TestCase
1320
{
1421
public function tearDown()
@@ -79,7 +86,7 @@ public function the_correct_length_is_returned_when_a_length_is_set()
7986
/** @test */
8087
public function insert_and_update_bust_the_cache_when_busting_is_enabled()
8188
{
82-
$model = Mockery::mock('Model[queryCache]')
89+
$model = Mockery::mock('BustingModel[queryCache]')
8390
->shouldAllowMockingProtectedMethods();
8491

8592
$queryCache = Mockery::mock(QueryCache::class);
@@ -90,8 +97,6 @@ public function insert_and_update_bust_the_cache_when_busting_is_enabled()
9097
->once()
9198
->andReturn($queryCache);
9299

93-
$model->bust();
94-
95100
$model->finishSave([]);
96101
}
97102

@@ -104,15 +109,13 @@ public function insert_and_update_do_not_bust_the_cache_when_busting_is_disabled
104109
$model->shouldReceive('queryCache')
105110
->times(0);
106111

107-
$model->dontBust();
108-
109112
$model->finishSave([]);
110113
}
111114

112115
/** @test */
113116
public function delete_should_bust_the_cache_when_busting_is_enabled()
114117
{
115-
$model = Mockery::mock('Model[queryCache]')
118+
$model = Mockery::mock('BustingModel[queryCache]')
116119
->shouldAllowMockingProtectedMethods();
117120

118121
$queryCache = Mockery::mock(QueryCache::class);
@@ -123,8 +126,6 @@ public function delete_should_bust_the_cache_when_busting_is_enabled()
123126
->once()
124127
->andReturn($queryCache);
125128

126-
$model->bust();
127-
128129
$model->delete();
129130
}
130131

@@ -137,28 +138,23 @@ public function delete_should_not_bust_the_cache_when_busting_is_disabled()
137138
$model->shouldReceive('queryCache')
138139
->times(0);
139140

140-
$model->dontBust();
141-
142141
$model->delete();
143142
}
144143

145144
/** @test */
146-
public function bust_enables_cache_busting()
145+
public function flush_empties_the_cache()
147146
{
148-
$model = new Model;
149-
150-
$model->bust();
151-
152-
$this->assertTrue($model->isBusting());
153-
}
147+
$model = Mockery::mock('BustingModel[queryCache]')
148+
->shouldAllowMockingProtectedMethods();
154149

155-
/** @test */
156-
public function dont_bust_disables_cache_busting()
157-
{
158-
$model = new Model;
150+
$queryCache = Mockery::mock(QueryCache::class);
151+
$queryCache->shouldReceive('flush')
152+
->once();
159153

160-
$model->dontBust();
154+
$model->shouldReceive('queryCache')
155+
->once()
156+
->andReturn($queryCache);
161157

162-
$this->assertFalse($model->isBusting());
158+
$model->flush();
163159
}
164160
}

0 commit comments

Comments
 (0)