Skip to content

Commit 60611fe

Browse files
committed
Initial commit on cache repository
1 parent 60e3cce commit 60611fe

20 files changed

+974
-22
lines changed

.gitignore

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
/vendor/
2-
node_modules/
3-
npm-debug.log
4-
yarn-error.log
5-
6-
# Laravel 4 specific
7-
bootstrap/compiled.php
8-
app/storage/
9-
10-
# Laravel 5 & Lumen specific
11-
public/storage
12-
public/hot
13-
14-
# Laravel 5 & Lumen specific with changed public path
15-
public_html/storage
16-
public_html/hot
17-
18-
storage/*.key
19-
.env
20-
Homestead.yaml
21-
Homestead.json
22-
/.vagrant
1+
vendor/
2+
.idea/
3+
composer.lock
234
.phpunit.result.cache

LICENSE renamed to LICENSE.md

File renamed without changes.

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "codeofdigital/cache-repository",
3+
"description": "Laravel Repository Package with Caching",
4+
"homepage": "https://github.com/codeofdigital/cache-repository",
5+
"keywords": [
6+
"codeofdigital",
7+
"laravel",
8+
"cache",
9+
"repository",
10+
"design pattern",
11+
"model",
12+
"SOLID"
13+
],
14+
"type": "library",
15+
"license": "MIT",
16+
"authors": [
17+
{
18+
"name": "Bryan Adam Loh",
19+
"email": "bryanadamloh97@gmail.com"
20+
}
21+
],
22+
"require": {
23+
"illuminate/http": "~5.0|~6.0|~7.0|^8.0|^9.0",
24+
"illuminate/config": "~5.0|~6.0|~7.0|^8.0|^9.0",
25+
"illuminate/support": "~5.0|~6.0|~7.0|^8.0|^9.0",
26+
"illuminate/database": "~5.0|~6.0|~7.0|^8.0|^9.0",
27+
"illuminate/pagination": "~5.0|~6.0|~7.0|^8.0|^9.0",
28+
"illuminate/console": "~5.0|~6.0|~7.0|^8.0|^9.0",
29+
"illuminate/filesystem": "~5.0|~6.0|~7.0|^8.0|^9.0",
30+
"illuminate/validation": "~5.0|~6.0|~7.0|^8.0|^9.0"
31+
},
32+
"require-dev": {
33+
"orchestra/testbench": "^4.0|^5.0|^6.0",
34+
"phpunit/phpunit": "^8.2"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"CodeOfDigital\\CacheRepository\\": "src/"
39+
}
40+
},
41+
"scripts": {
42+
"tests": "./vendor/bin/phpunit --colors=always"
43+
},
44+
"extra": {
45+
"laravel": {
46+
"providers": [
47+
"CodeOfDigital\\CacheRepository\\CacheRepositoryServiceProvider"
48+
]
49+
}
50+
}
51+
}

config/repository.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Repository Pagination Limit Default
8+
|--------------------------------------------------------------------------
9+
|
10+
*/
11+
'pagination' => [
12+
'limit' => 15
13+
],
14+
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Cache Config
18+
|--------------------------------------------------------------------------
19+
|
20+
*/
21+
'cache' => [
22+
/*
23+
|--------------------------------------------------------------------------
24+
| Cache Status
25+
|--------------------------------------------------------------------------
26+
|
27+
| Enable or disable cache
28+
|
29+
*/
30+
'enabled' => false,
31+
32+
/*
33+
|--------------------------------------------------------------------------
34+
| Cache Minutes
35+
|--------------------------------------------------------------------------
36+
|
37+
| Time of expiration cache
38+
|
39+
*/
40+
'minutes' => 30,
41+
42+
/*
43+
|--------------------------------------------------------------------------
44+
| Cache Repository
45+
|--------------------------------------------------------------------------
46+
|
47+
| Instance of Illuminate\Contracts\Cache\Repository
48+
|
49+
*/
50+
'repository' => 'cache',
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| Cache Clean Listener
55+
|--------------------------------------------------------------------------
56+
|
57+
|
58+
|
59+
*/
60+
'clean' => [
61+
62+
/*
63+
|--------------------------------------------------------------------------
64+
| Enable clear cache on repository changes
65+
|--------------------------------------------------------------------------
66+
|
67+
*/
68+
'enabled' => true,
69+
70+
/*
71+
|--------------------------------------------------------------------------
72+
| Actions in Repository
73+
|--------------------------------------------------------------------------
74+
|
75+
| create : Clear Cache on create Entry in repository
76+
| update : Clear Cache on update Entry in repository
77+
| delete : Clear Cache on delete Entry in repository
78+
|
79+
*/
80+
'on' => [
81+
'create' => true,
82+
'update' => true,
83+
'delete' => true,
84+
]
85+
],
86+
87+
'params' => [
88+
/*
89+
|--------------------------------------------------------------------------
90+
| Skip Cache Params
91+
|--------------------------------------------------------------------------
92+
|
93+
|
94+
| Ex: http://prettus.local/?search=lorem&skipCache=true
95+
|
96+
*/
97+
'skipCache' => 'skipCache'
98+
],
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| Methods Allowed
103+
|--------------------------------------------------------------------------
104+
|
105+
| methods cacheable : all, paginate, find, findByField, findWhere, getByCriteria
106+
|
107+
| Ex:
108+
|
109+
| 'only' =>['all','paginate'],
110+
|
111+
| or
112+
|
113+
| 'except' =>['find'],
114+
*/
115+
'allowed' => [
116+
'only' => null,
117+
'except' => null
118+
]
119+
],
120+
];

phpunit.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnError="false"
11+
stopOnFailure="true"
12+
verbose="true">
13+
<testsuites>
14+
<testsuite name="Cache Repository Test Suite">
15+
<directory suffix="Test.php">tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src/</directory>
21+
</whitelist>
22+
</filter>
23+
<php>
24+
<env name="APP_ENV" value="testing"/>
25+
</php>
26+
</phpunit>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace CodeOfDigital\CacheRepository;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class CacheRepositoryServiceProvider extends ServiceProvider
8+
{
9+
public function boot()
10+
{
11+
12+
}
13+
}

src/Contracts/CacheableInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace CodeOfDigital\CacheRepository\Contracts;
4+
5+
use Illuminate\Contracts\Cache\Repository as CacheRepository;
6+
7+
interface CacheableInterface
8+
{
9+
public function setCacheRepository(CacheRepository $repository): static;
10+
11+
public function getCacheRepository(): CacheRepository;
12+
13+
public function getCacheKey($method, $args = null): string;
14+
15+
public function getCacheTime(): int;
16+
17+
public function skipCache($status = true): static;
18+
}

src/Contracts/RepositoryInterface.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace CodeOfDigital\CacheRepository\Contracts;
4+
5+
use Closure;
6+
7+
interface RepositoryInterface
8+
{
9+
public function pluck($column, $key = null);
10+
11+
public function sync($id, $relation, $attributes, $detaching = true);
12+
13+
public function syncWithoutDetaching($id, $relation, $attributes);
14+
15+
public function all($columns = ['*']);
16+
17+
public function paginate($limit = null, $columns = ['*']);
18+
19+
public function simplePaginate($limit = null, $columns = ['*']);
20+
21+
public function find($id, $columns = ['*']);
22+
23+
public function findByField($field, $value, $columns = ['*']);
24+
25+
public function findWhere(array $where, $columns = ['*']);
26+
27+
public function findWhereIn($field, array $values, $columns = ['*']);
28+
29+
public function findWhereNotIn($field, array $values, $columns = ['*']);
30+
31+
public function findWhereBetween($field, array $values, $columns = ['*']);
32+
33+
public function create(array $attributes);
34+
35+
public function update(array $attributes, $id);
36+
37+
public function updateOrCreate(array $attributes, array $values = []);
38+
39+
public function delete(int $id);
40+
41+
public function orderBy($column, $direction = 'asc');
42+
43+
public function with($relations);
44+
45+
public function whereHas(string $relation, Closure $closure);
46+
47+
public function withCount($relations);
48+
49+
public function hidden(array $fields);
50+
51+
public function visible(array $fields);
52+
53+
public function scopeQuery(Closure $scope);
54+
55+
public function resetScope();
56+
57+
public function firstOrNew(array $attributes = []);
58+
59+
public function firstOrCreate(array $attributes = []);
60+
61+
public static function __callStatic($method, $arguments);
62+
63+
public function __call($method, $arguments);
64+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace CodeOfDigital\CacheRepository\Contracts;
4+
5+
interface TransformerInterface
6+
{
7+
public function transform(): array;
8+
}

0 commit comments

Comments
 (0)