0

I have a questions about Redis cache and laravel. By default laravel uses file which caches views to a file and load them from that cache.

Now here's the thing, I started using ElastiCache with Redis for my Laravel 5.4 project. If I change the driver to redis and it starts to cache (which I can tell by a loading time) but what does it actually cache? Does it automatically cache and retrieve my views? css? js? anything else?

I am also using redis for sessions driver, what does that give me?

Is it worth caching database as well? I was planning to cache whole database every hour and then whenever new item is added to database, add it to the existing cache. Is that possible?

Przemek Wojtas
  • 1,311
  • 5
  • 26
  • 51

1 Answers1

1

The redis could give you two advantages:

  1. faster data retrieving. Any memory-based cache system can give you this advantage than file-based or DB-based, such as memcached.
  2. flexible data saving in redis. redis support many data-type store such as string, list, set, sorted-set and so on.

About caching what?

  1. Cache the frequent request thing. If your client request something or query something to you, and you do not have cache, you will have to query it from your database, which give you an disk I/O time cost. And if the thing is heavy, then the IO cost will be bigger and slow down your server. So the smart way is , just query once and then save it into redis by suitable data-type store. After that retrive thousands with Cache. But you do not need to cache the overall database. It looks rude. And when you update something in db, just delete from your cache and after next time someone query this, it will save into cache again.

  2. About Session. this is very frequent access thing for http server , so every user'session into cache is more light weight than file or db if your app server many many many people.

  3. Cache the static file. Actually I has not dealt with this. But it can do this definitely! E.g. In modern architecture, there is often a Http server stand before your laravel such as nginx. In this way, you will use nginx serve the static file directly. And if you want decrease the disk io about this, you can add a module like redis2-nginx-module for nginx to do a same thing : save the static file into redis once and serve thousands.

GuangshengZuo
  • 4,447
  • 21
  • 27