1. Go to this page and download the library: Download lotestudio/model-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/ */
use Lotestudio\ModelCache\Facades\ModelCache;
// Get all cached stores
$stores = ModelCache::all('stores');
// Find a specific store by ID
$store = ModelCache::find('stores', 1);
// Find by custom field
$store = ModelCache::findBy('stores', 'email', '[email protected]');
// Find all matching a condition
$activeStores = ModelCache::findAllBy('stores', 'is_active', true);
// Check existence
if (ModelCache::exists('stores', 1)) {
// ...
}
// Clear cache for a specific model
ModelCache::clear('stores');
// Clear all caches
ModelCache::clearAll();
// Warm up cache
ModelCache::warmup('stores');
ModelCache::warmupAll();
// Equivalent to ModelCache::find('stores', $id)
ModelCache::findStores($id);
// Equivalent to ModelCache::all('stores')
ModelCache::allStores();
// Equivalent to ModelCache::clear('stores')
ModelCache::clearStores();
// Get the cache instance
$cache = model_cache();
// Find a cached model by ID
$store = model_cached('stores', 1);
// Get all cached models
$stores = model_cached_all('stores');
// Find by custom field
$store = model_cached_find_by('stores', 'slug', 'main-store');
// Find all matching
$items = model_cached_find_all_by('stores', 'is_active', true);
// Check existence
$exists = model_cached_exists('stores', 1);
// Clear cache
model_cache_clear('stores');
model_cache_clear_all();
// Warm up cache
model_cache_warmup('stores');
model_cache_warmup_all();
// Get statistics
$stats = model_cache_stats();
$storeStats = model_cache_stats('stores');
// Register a model dynamically
model_cache_register('products', [
'model' => App\Models\Product::class,
'key' => 'products',
'order_by' => 'name',
]);
use Lotestudio\ModelCache\Contracts\ModelCacheInterface;
class StoreController
{
public function __construct(
protected ModelCacheInterface $cache
) {}
public function index()
{
$stores = $this->cache->all('stores');
return view('stores.index', compact('stores'));
}
}