1. Go to this page and download the library: Download salibhdr/typhoon-cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
salibhdr / typhoon-cache example snippets
'providers' => [
// Other service providers...
SaliBhdr\TyphoonCache\ServiceProviders\TyphoonCacheServiceProvider::class,
],
// App\Book.php
/**
* if you want to customize what you want to cache just override this method
*
* @return Model
*/
public function toCacheable()
{
// method 1
return $this;
// method 2
return $this->toArray();
// method 3
return [
'title' => $this->title
'author' => $this->author
]; // returns data only with these two attributes
}
// In controller
// if you want 1 record
public function getBook(Request $request)
{
$book = Book::findOrFail($request->get('book_id'));
dd($book->isCachedData()); // returns true if its cached data
}
//if you want multipul records
public function getBooks(Request $request)
{
$books = Book::get();
foreach($books as $book)
dd($book->isCachedData()); // returns true if its cached data
}
// In controller
use SaliBhdr\TyphoonCache\Facades\TyphoonCache
use App\Book
public function getBook(Request $request)
{
// first parametr is the model that you the data is related to.
// second argument is the records id
// third argument (optional) : if is_based_on_user option in config file is set to true
$book = TyphoonCache::retrieveModel(Book::class,$request->get('book_id'),auth()->id());
dd($book->isCachedData()); // returns true if its cached data
}