Skip to content

Commit

Permalink
Refactor cache
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Apr 24, 2020
1 parent 7c45cbc commit d28db90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public function queue()

public function batch()
{
config(['cache.default' => 'array']);

$data = Cache::tags(['collector'])->get('collector');
$data = Cache::get('collector');

if(is_array($data)){
$data[] = $this->metric;
Expand All @@ -70,6 +69,6 @@ public function batch()
$data[] = $this->metric;
}

Cache::tags(['collector'])->put('collector', $data);
Cache::put('collector', $data);
}
}
6 changes: 2 additions & 4 deletions src/Jobs/BatchMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public function __construct()
public function handle()
{

config(['cache.default' => 'array']);

$metrics = Cache::tags(['collector'])->get('collector');
$metrics = Cache::get('collector');

$generator = new Generator();
$generator->batchFire($metrics);

Cache::tags(['collector'])->flush();
Cache::forget('collector');

}
}
4 changes: 3 additions & 1 deletion src/Jobs/CreateMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Turbo124\Collector\Collector\Generator;

class CreateMetric
{
Expand All @@ -29,6 +30,7 @@ public function __construct($metric)
*/
public function handle()
{

$generator = new Generator();
$generator->fire($this->metric);
}
}
8 changes: 3 additions & 5 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public function testCacheGetAndPut()
{
$test_array = ['a' => 'b', 'c'=>'d'];

config(['cache.default' => 'array']);

$data = Cache::tags(['collector'])->get('collector');
$data = Cache::get('collector');

if(is_array($data)){
$data[] = $test_array;
Expand All @@ -27,9 +25,9 @@ public function testCacheGetAndPut()
$data[] = $test_array;
}

Cache::tags(['collector'])->put('collector', $data);
Cache::put('collector', $data);

$test_data = Cache::tags(['collector'])->get('collector');
$test_data = Cache::get('collector');

$this->assertTrue(is_array($test_data));

Expand Down

0 comments on commit d28db90

Please sign in to comment.