Last active
September 22, 2016 06:41
-
-
Save Omranic/36e383535f95fbad1ec1bfc7e0610dc8 to your computer and use it in GitHub Desktop.
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain. https://github.com/rinvex/repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Repositories\UserRepository; | |
class UsersController | |
{ | |
public function baz(UserRepository $users) | |
{ | |
// Find entity by primary key | |
$users->find(1); | |
// Find all entities | |
$users->findAll(); | |
// Cache this individual query with redis (regardless of default cache driver) | |
$users->setCacheDriver('redis')->whereIn('id', [1, 2, 5, 8]); | |
// Cache this individual query for 123 minutes (regardless of default cache lifetime) | |
$users->setCacheLifetime(123)->whereNotIn('id', [1, 2, 5, 8]); | |
// Find user with username equal tester, but don't cache the result | |
$users->setCacheLifetime(0)->findBy('username', 'tester'); | |
// Execute complex query logix, and cache results granularly with flexibility | |
$users->with('roles') // Retrieve roles relation as well | |
->where('username', '!=', 'test') // Find users with username != test | |
->where('first_name', '%like%', 'Test') // Find users with first name like Test | |
->whereNotIn('id', [1, 2, 5, 8]) // Find users with id not in 1, 2, 5, 8 | |
->offset(5) // Skip first 5 results | |
->limit(9) // Limit results to 9 records | |
->orderBy('id', 'asc') // Order results ascending by id | |
->setCacheDriver('redis') // Cache results using redis | |
->setCacheLifetime(123); // Cache results for 123 minutes | |
// Create a new entity with name attribute | |
$users->create(['name' => 'Example']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand why in these examples you don't use ->get()
This is not working for me
$product->featured()->limit(2)->get();
Featured() is a scope and I'm using https://github.com/jenssegers/laravel-mongodb with get() I don't see any caching at all. And without like your examples it's not working for me.
Can you help me?