How to store all records in laravel 5.3 Cache

How to store all records in laravel 5.3 Cache

How to store all records in laravel 5.3 Cache

In this tutorials, i am going to tell you how to work with cache in Laravel.

You can easily save database record in cache and easily you can get that record from cache in Laravel.

Cache is knows as persistence layer between database and application and it is used to improve website performance because sometime database query is going very slow due to lots of traffic at same time on website then retrieving data from cache is much quicker rather than from a database.

Memcached is know as very popular caching system which is used by many high trafficked websites.

Putting an item in the cache

We can easily add or update value in cache by using put() method and we pass 3 parameters in this method.

Cache::put('key', 'value', 30);

In 3rd parameters we pass expiration time in minutes.

Getting an item from the cache

We can easily get item from cache and also we can check if cache has the key you are looking for.

  1. if( Cache::has( 'key' ) ) {
  2. return Cache::get( 'key' );
  3. }
Model::remember()

We use remember() to cache the database result while querying from database.

$users = User::remember(10)->get();

Sometime you want to retrieve data from cache but requested data does not exist in cache then store default data in cache.

  1. $allproducts = Cache::remember('allproducts',60, function() {
  2. return DB::table('products')->get();
  3. });
Removing Cache records

You can remove records from cache using forget method.

Cache::forget('allproducts');

You can clear entire records from cache using flush method.

Cache::flush();

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort