Skip to content

Commit

Permalink
added support for 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Isler committed Jul 20, 2017
1 parent e38135d commit d208816
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Unreleased]

## [2.0] - 2017-07-20
### Changed
- Now using a trait instead of a base model class

### Added
- Added support for Laravel 5.4

## [1.4.2] - 2016-12-09
### Fixed
- Fixed bug in debug bar collector
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Matthias Isler
Copyright (c) 2017 Matthias Isler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A Redis based, automated and scalable database caching layer for Laravel 5.1+
- Intelligent cache invalidation with high granularity
- Works with existing code, no changes required after setup
- Possibility to cache only specific models or exclude some models
- Makes use of [Laravel Redis](http://laravel.com/docs/5.3/redis) (supports [clustering](https://laravel.com/docs/5.3/redis#introduction))
- Makes use of [Laravel Redis](http://laravel.com/docs/5.4/redis) (supports [clustering](https://laravel.com/docs/5.4/redis#introduction))
- Supports PHP7

## Performance
Expand All @@ -37,7 +37,7 @@ This library offers a solution for all of these problems.

## Why only Redis?

As you may have discovered while looking at the source code, this library is built directly on top of [Laravel Redis](http://laravel.com/docs/5.3/redis) and not [Laravel Cache](http://laravel.com/docs/5.3/cache) which would make more sense from a general point of view.
As you may have discovered while looking at the source code, this library is built directly on top of [Laravel Redis](http://laravel.com/docs/5.4/redis) and not [Laravel Cache](http://laravel.com/docs/5.4/cache) which would make more sense from a general point of view.
However, there are several important reasons behind this decision:

- Storage must be in-memory (wouldn't make much sense otherwise)
Expand All @@ -48,7 +48,7 @@ If you still want to use another storage backend, please feel free to contribute

## Requirements

- PHP 5.5+
- PHP 5.6+
- Redis 2+
- Laravel 5.1+
- [Predis](https://github.com/nrk/predis)
Expand All @@ -74,16 +74,19 @@ Find the `providers` key in your `config/app.php` and register the Lada Cache Se
)
```

Finally, all your models must extend the `Spiritix\LadaCache\Database\Model` class.
It's a good practice to create a base model class which extends the Lada Cache model and then gets extended by all your models.
Finally, all your models must include the `Spiritix\LadaCache\Database\LadaCacheTrait` trait.
It's a good practice to create a base model class which includes the trait and then gets extended by all your models.

```php
class Post extends Spiritix\LadaCache\Database\Model {
//
class Car extends \Illuminate\Database\Eloquent\Model {

use \Spiritix\LadaCache\Database\LadaCacheTrait;

// ...
}
```

_Don't try to only have specific models extending the Lada Cache model, it will result in unexpected behavior.
_Don't try to only have specific models including the Lada Cache trait, it will result in unexpected behavior.
In the configuration, you will find the possibility to include or exclude specific models._

## Configuration
Expand Down Expand Up @@ -111,7 +114,7 @@ php artisan lada-cache:enable

## Known issues and limitations

- Does not work with [raw SQL queries](http://laravel.com/docs/5.3/database#running-queries). This would require an SQL parser to be implemented which is quite hard and very inefficient. As long as you are only using raw queries for reading data, it just won't get cached. Serious issues will only occur if you use raw queries for writing data (which you shouldn't be doing anyway).
- Does not work with [raw SQL queries](http://laravel.com/docs/5.4/database#running-queries). This would require an SQL parser to be implemented which is quite hard and very inefficient. As long as you are only using raw queries for reading data, it just won't get cached. Serious issues will only occur if you use raw queries for writing data (which you shouldn't be doing anyway).
- Invalidation on row level [does only work](https://github.com/spiritix/lada-cache/issues/16) if you use ``id`` as column name for your primary keys.
- The cache must be truncated manually after migrations are executed.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.5.9",
"php": ">=5.6.4",
"illuminate/support": "~5.1",
"illuminate/database": "~5.1",
"illuminate/redis": "~5.1",
Expand Down
34 changes: 28 additions & 6 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spiritix\LadaCache\Tests;

use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Laracasts\TestDummy\Factory;
use Spiritix\LadaCache\LadaCacheServiceProvider;
Expand All @@ -11,14 +12,30 @@ class TestCase extends \Orchestra\Testbench\TestCase
{
protected $factory;

private $useArtisan;

public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);

$this->useArtisan = version_compare('5.4', Application::VERSION, '>');
}

public function setUp()
{
parent::setUp();

$this->loadMigrationsFrom([
$migrationParams = [
'--database' => 'testing',
'--realpath' => realpath(__DIR__.'/../database/migrations'),
]);
'--realpath' => realpath(__DIR__ . '/../database/migrations'),
];

if ($this->useArtisan) {
$this->artisan('migrate', $migrationParams);
}
else {
$this->loadMigrationsFrom($migrationParams);
}

$this->factory = new Factory(__DIR__ . '/../database/factories');

Expand All @@ -34,10 +51,15 @@ public function tearDown()

protected function getPackageProviders($app)
{
return [
LadaCacheServiceProvider::class,
ConsoleServiceProvider::class
$providers = [
LadaCacheServiceProvider::class
];

if (!$this->useArtisan) {
$providers[] = ConsoleServiceProvider::class;
}

return $providers;
}

protected function getEnvironmentSetUp($app)
Expand Down

0 comments on commit d208816

Please sign in to comment.