The cache storage method in tp5, my local setting is to read text.
Take this code as an example: (Recommended learning: thinkphp5)
public function getAllManegerId(){ $cache =checkCache('kf_getallManeger'); if($cache)return$cache; $role = Db::table('customer_role')->where(['type'=>2, 'role_status'=>0,])->select(); $array = []; if(!empty($role)){ foreach ($role as $key=>$value){ $customer = Db::table('customer')->where(['role_id'=>$value['role_id'],'user_status'=>0])->select(); foreach ($customer as $keys=>$values){ array_push($array,$values['customer_id']); } } } \cache('kf_getallManeger',$array,300); return $array; }
There are two loops here, if no caching is used It basically takes 400–600ms to process the information.
After adding the cache that comes with tp, the time spent is significantly shortened, between 40-60ms, which is ideal.
After writing this, I wonder if redis will be around 10ms, which will be more powerful than the built-in cache.
So I added redis cache
$redis = $this->redis = new \Redis; $redis->connect('127.0.0.1', 6379); $caches = $redis->get('kf_getallManeger'); if($caches)return $caches;
On the surface it is basically the same as tp’s cache method, but in fact there is concurrency, and the traffic has not been tested
The conclusion is:
If the amount of storage is not large, TP's file cache is similar to redis. But memory reading must be faster. If there are many values stored, redis's powerful I/O capabilities will be stronger than ordinary file reading and writing.
The above is the detailed content of Which one is faster, thinkphp cache or redis cache?. For more information, please follow other related articles on the PHP Chinese website!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.