Skip to content

Commit 8529000

Browse files
committed
Update readme, changelog, and issue template
1 parent ea787dd commit 8529000

File tree

4 files changed

+138
-16
lines changed

4 files changed

+138
-16
lines changed

Diff for: CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [0.1.0] - 2017-09-22
8+
### Added
9+
- initial development of package.
10+
- unit tests with 100% code coverage.

Diff for: CONTRIBUTING.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ However, not every pull request will automatically be accepted. I will review ea
1111
## Testing
1212
- [ ] After making your changes, make sure the tests still pass.
1313
- [ ] When adding new functionality, also add new tests.
14+
- [ ] When fixing errors write and satisfy new unit tests that replicate the issue.
1415
- [ ] Make sure there are no build errors on our CI server (https://ci.genealabs.com/build-status/view/8)
1516
- [ ] All code must past PHPCS and PHPMD PSR2 validation.
1617

1718
## Submitting changes
1819
When submitting a pull request, it is important to make sure to complete the following:
19-
- [ ] Add a descriptive header that explains in a single scentence what problem the PR solves.
20-
- [ ] Add a detailed description with animated screengrab GIFs vidualizing how it works.
20+
- [ ] Add a descriptive header that explains in a single sentence what problem the PR solves.
21+
- [ ] Add a detailed description with animated screen-grab GIFs visualizing how it works.
2122
- [ ] Explain why you think it should be implemented one way vs. another, highlight performance improvements, etc.
2223

2324
## Coding conventions

Diff for: ISSUE_TEMPLATE.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33

44
## Environment
55
Laravel Version: *x.y.z*
6-
Laravel Messenger Package Version: *x.y.z*
6+
Laravel Model Caching Package Version: *x.y.z*
77
PHP Version: *x.y.z*
88
Homestead Version: *x.y*
99
Operating System & Version: *name x.y.z*
1010

1111
## Stack Trace
12-
- [ ] I have cleared my Laravel log file.
13-
- [ ] I have then reproduced my issue.
14-
- [ ] I have copied the __first__ listed stack trace from the fresh log file.
15-
1612
```
17-
*paste the first stack trace here*
13+
*paste the relevant, complete stack trace here*
1814
```

Diff for: README.md

+123-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
** DO NOT INSTALL -- STILL IN EXPERIMENTAL STAGE**
2-
31
# Model Caching for Laravel
42
[![Travis](https://img.shields.io/travis/GeneaLabs/laravel-model-caching.svg)](https://travis-ci.org/GeneaLabs/laravel-model-caching)
53
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/fde269ac-c382-4d17-a647-c69ad6b9dd85.svg)](https://insight.sensiolabs.com/projects/fde269ac-c382-4d17-a647-c69ad6b9dd85)
@@ -8,10 +6,127 @@
86
[![GitHub (pre-)release](https://img.shields.io/github/release/GeneaLabs/laravel-model-caching/all.svg)](https://github.com/GeneaLabs/laravel-model-caching)
97
[![Packagist](https://img.shields.io/packagist/dt/GeneaLabs/laravel-model-caching.svg)](https://packagist.org/packages/genealabs/laravel-model-caching)
108

9+
## Impetus
10+
I created this package in response to a client project that had complex, nested
11+
forms with many `<select>`'s that resulted in over 700 database queries on one
12+
page. I needed a package that abstracted the caching process out of the model
13+
for me, and one that would let me cache custom queries, as well as cache model
14+
relationships. This package is the attempt to address those requirements.
15+
1116
## Features
12-
- automatic relationship caching.
13-
- automatic cache flushing when models are changed.
14-
- automatic use of cache flags for cache providers that support them (will flush
15-
entire cache for providers that don't).
16-
- provides simple caching methods for use in query methods for models that take
17-
advantage of the automatic cache management features mentioned.
17+
- automatic, self-invalidating relationship caching.
18+
- automatic use of cache flags for cache providers that support them (will
19+
flush entire cache for providers that don't).
20+
- provides simple caching methods for use in query methods for models that
21+
take advantage of the automatic cache management features mentioned.
22+
23+
## Requirements
24+
- PHP >= 7.0.0
25+
- Laravel 5.5
26+
27+
## Usage
28+
For best performance a taggable cache provider is recommended (redis,
29+
memcached). While this is optional, using a non-taggable cache provider will
30+
mean that the entire cache is cleared each time a model is created, saved,
31+
updated, or deleted.
32+
33+
For best implementation results, I would recommend adding a `BaseModel` model
34+
from which all your other models are extended. The BaseModel should extend from
35+
`CachedModel`.
36+
37+
### Automatic Relationship Caching
38+
When writing custom queries in your models, use `$this->cache()` instead of
39+
`cache()` to automatically tag and cache the queries. These will also be auto-
40+
invalidated.
41+
42+
```php
43+
<?php namespace App;
44+
45+
use GeneaLabs\LaravelModelCaching\CachedModel;
46+
47+
abstract class BaseModel extends CachedModel
48+
{
49+
//
50+
}
51+
```
52+
53+
```php
54+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
55+
use Illuminate\Support\Collection;
56+
57+
class Venue extends BaseModel
58+
{
59+
protected $fillable = [
60+
'name',
61+
];
62+
63+
public function address() : BelongsTo
64+
{
65+
return $this->belongsTo(Address::class);
66+
}
67+
68+
public function getAll() : Collection
69+
{
70+
return $this->cache()
71+
->rememberForever("venues-getAll", function () {
72+
return $this->orderBy('name')
73+
->get();
74+
});
75+
}
76+
}
77+
```
78+
79+
### Custom Query Caching
80+
**`$this->cache(array $keys)`**
81+
This method is available in any model that extends `CachedModel`, as well
82+
as automatically invalidate them. Pass in respective additional models that are
83+
represented in the query being cached. This is most often necessary when eager-
84+
loading relationships.
85+
86+
When you create the cache key, be sure to build the key in such a way that it
87+
uniquely represents the query and does not overwrite keys of other queries. The
88+
best way to achieve this is to build the key as follows: `<model slug>-<model
89+
method>-<unique key>`. The `unique key` portion is only necessary if you pass in
90+
parameters for your query where clauses.
91+
92+
```php
93+
public function getByTypes(array $types) : Collection
94+
{
95+
$key = implode('-', $types);
96+
97+
return $this->cache([ContactType::class])
98+
->rememberForever("contacts-getByTypes-{$key}", function () use ($types) {
99+
return $this
100+
->with(['contactTypes' => function ($query) use ($types) {
101+
$query->whereIn('title', $types);
102+
}])
103+
->orderBy('name')
104+
->get();
105+
});
106+
}
107+
```
108+
109+
## Dedication to Quality
110+
During package development I try as best as possible to embrace good design and
111+
development practices to try to ensure that this package is as good as it can
112+
be. My checklist for package development includes:
113+
114+
- ✅ Achieve as close to 100% code coverage as possible using unit tests.
115+
- ✅ Eliminate any issues identified by SensioLabs Insight and Scrutinizer.
116+
- ✅ Be fully PSR1, PSR2, and PSR4 compliant.
117+
- ✅ Include comprehensive documentation in README.md.
118+
- ✅ Provide an up-to-date CHANGELOG.md which adheres to the format outlined
119+
at <http://keepachangelog.com>.
120+
- ✅ Have no PHPMD or PHPCS warnings throughout all code.
121+
122+
## Contributing
123+
Please observe and respect all aspects of the included Code of Conduct <https://github.com/GeneaLabs/laravel-model-caching/blob/master/CODE_OF_CONDUCT.md>.
124+
125+
### Reporting Issues
126+
When reporting issues, please fill out the included template as completely as
127+
possible. Incomplete issues may be ignore or closed if there is not enough
128+
information included to be actionable.
129+
130+
### Submitting Pull Requests
131+
Please review the Contribution Guidelines <https://github.com/GeneaLabs/laravel-model-caching/blob/master/CONTRIBUTING.md>.
132+
Only PRs that meet all criterium will be accepted.

0 commit comments

Comments
 (0)