×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÔÚthinkphpÖÐɾ³ý»º´æ

ÔÚʹÓÃthinkphp¾ÙÐпª·¢Ê± £¬Ê¹Óûº´æ¿ÉÒÔÌá¸ßÍøÕ¾ÐÔÄÜ £¬ïÔÌ­Êý¾Ý¿âÅÌÎʵĴÎÊý £¬ÌáÉýÍøÕ¾ÏìÓ¦ËÙÂÊ¡£¿ÉÊÇ £¬ÈôÊÇ»º´æÓâÆÚʱ¼äÉèÖò»µ±»òÕß»º´æÊý¾Ý±¬·¢×ª±ä £¬¾ÍÐèÒª¾ÙÐлº´æɾ³ý²Ù×÷¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphpÖÐɾ³ý»º´æ¡£

»º´æÓâÆÚʱ¼äÉèÖÃ

ÔÚʹÓÃthinkphp¾ÙÐлº´æ²Ù×÷ʱ £¬ÐèÒªÖ¸¶¨»º´æÓâÆÚʱ¼ä¡£¿ÉÒÔÔÚconfigĿ¼ÏµÄcache.phpÎļþÖоÙÐÐÉèÖᣴúÂëÈçÏ£º

return [
    // Ä¬ÈÏÉèÖõĻº´æ
    'default' => env('cache.driver', 'file'),

    // »º´æÅþÁ¬²ÎÊý
    'stores' => [
        // Îļþ»º´æ
        'file' => [
            'driver' => 'file',
            'path'   => env('cache.path', app()->getRuntimePath() . 'cache'),
        ],

        // Redis»º´æ
        'redis' => [
            'driver' => 'redis',
            'host'   => env('cache.redis.host', '127.0.0.1'),
            'port'   => env('cache.redis.port', 6379),
            'password' => env('cache.redis.password', ''),
            'select' => env('cache.redis.select', 0),
            'timeout' => env('cache.timeout', 0),
            'expire' => env('cache.expire', 0),
            'persistent' => env('cache.redis.persistent', false),
            'prefix' => '',
            'serialize' => [],
        ],
    ],

    // »º´æÉèÖÃ
    'cache' => [
        // Çý¶¯·½·¨
        'type'  => 'File',
        // »º´æÉúÑÄĿ¼
        'path'  => '../runtime/cache/',
        // »º´æǰ׺
        'prefix'=> '',
        // »º´æÓÐÓÃÆÚ 0ÌåÏÖÓÀÊÀ»º´æ
        'expire'=> 0,
    ],
];

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬cache.phpÎļþÖеÄÉèÖÃÏºÜÊÇÏÔ×Å¡£¸÷¸öÉèÖÃÏîµÄ¼ÄÒåÈçÏ£º

default£ºÄ¬ÈϵĻº´æÀàÐÍ £¬¿ÉÒÔƾָ֤¶¨ÇéÐαäÁ¿ÀïµÄcache.driverµÄֵΪfile¡¢redisµÈ¡£

stores£ºÖ§³Ö¶àÖÖÀàÐ͵Ļº´æ £¬Îļþ»º´æºÍRedis»º´æ¡£

driver£ºÖ¸¶¨»º´æÀàÐÍ £¬Èçfile¡¢redisµÈ¡£

cache£ºÉèÖûº´æÊôÐÔ¡£

ÔÚÏêϸµÄÓªÒµ´úÂëÖÐ £¬Ê¹ÓÃCacheÀà¾ÙÐлº´æ²Ù×÷¡£ÀýÈç £¬ÔÚÉèÖûº´æʱ £¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺

use think\facade\Cache;

// ÉèÖûº´æ
Cache::set('key', 'value', 3600);

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬setÒªÁìµÄµÚÒ»¸ö²ÎÊýΪkey £¬µÚ¶þ¸ö²ÎÊýΪvalue £¬µÚÈý¸ö²ÎÊýΪ»º´æÓâÆÚʱ¼ä £¬µ¥Î»ÊÇÃë¡£ÉèÖÃÍ껺´æºó £¬¿ÉÒÔʹÓÃgetÒªÁì»ñÈ¡»º´æÊý¾Ý¡£ÀýÈ磺

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

use think\facade\Cache;

// »ñÈ¡»º´æ
$value = Cache::get('key');

µÇ¼ºó¸´ÖÆ

»º´æɾ³ý

µ±»º´æÊý¾ÝÓâÆÚ»òÕß±¬·¢×ª±äʱ £¬ÐèÒª¾ÙÐлº´æɾ³ý²Ù×÷¡£thinkphpÌṩÁËdeleteÒªÁìÓÃÓÚɾ³ý»º´æ¡£ÀýÈ磺

use think\facade\Cache;

// É¾³ý»º´æ
Cache::delete('key');

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬deleteÒªÁìµÄ²ÎÊýΪ»º´æµÄkey £¬¼´ÎªÐèҪɾ³ýµÄ»º´æµÄÃû³Æ¡£

ÔÚ¾ÙÐÐÄ£¿é»¯¿ª·¢Ê± £¬ÐèҪɾ³ýij¸öÄ£¿éϵÄËùÓлº´æÊý¾Ý¡£ÀýÈ磺

use think\facade\Cache;

// É¾³ýij¸öÄ£¿éϵÄËùÓлº´æÊý¾Ý
Cache::clear('module');

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬clearÒªÁìµÄ²ÎÊýΪÄ£¿éÃû³Æ £¬¼´ÎªÐèҪɾ³ý»º´æµÄÄ£¿éÃû¡£ÔÚ¾ÙÐлº´æɾ³ý²Ù×÷ʱ £¬ÐèҪȷ±£É¾³ýµÄ»º´æÃû³ÆºÍÉèÖûº´æʱµÄÃû³ÆÒ»Ö £¬²»È»ÎÞ·¨É¾³ýÒÑÉèÖõĻº´æ¡£

»º´æʧЧ

ÔÚijЩÇéÐÎÏ £¬ÐèÒªÈÃËùÓеĻº´æÊý¾ÝʧЧ £¬ÕâʱÐèҪʹÓûº´æµÄflushÒªÁì¡£ÀýÈ磺

use think\facade\Cache;

// Ê§Ð§ËùÓлº´æÊý¾Ý
Cache::clear();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬clearÒªÁì²»´ø²ÎÊý £¬¼´¿ÉʧЧËùÓеĻº´æÊý¾Ý¡£ÔÚ¾ÙÐлº´æÇå¿Õ²Ù×÷ʱ £¬ÐèÒªÉóÉ÷²Ù×÷ £¬×èÖ¹Îóɾ»º´æÊý¾Ý¡£

×ܽ᣺

ÔÚʹÓÃthinkphp¾ÙÐпª·¢Ê± £¬»º´æÊÇÌá¸ßÍøÕ¾ÐÔÄܵÄÖ÷ÒªÊֶΡ£ÔÚ»º´æÓâÆÚ»òÕßÊý¾Ý±¬·¢×ª±äʱ £¬ÐèÒª¾ÙÐлº´æɾ³ý²Ù×÷¡£thinkphpÌṩÁËɨ³ýij¸öÄ£¿é»òËùÓÐÄ£¿éµÄ»º´æÒªÁì £¬ÒÔ¼°Ê§Ð§ËùÓлº´æÊý¾ÝµÄÒªÁì¡£ÔÚ¾ÙÐлº´æɾ³ý²Ù×÷ʱ £¬ÐèҪȷ±£É¾³ýµÄ»º´æÃû³ÆºÍÉèÖûº´æʱµÄÃû³ÆÒ»Ö¡£ÔÚ¾ÙÐлº´æÇå¿Õ²Ù×÷ʱ £¬ÐèÒªÉóÉ÷²Ù×÷ £¬×èÖ¹Îóɾ»º´æÊý¾Ý¡£

ÒÔÉϾÍÊÇÔõÑùÔÚthinkphpÖÐɾ³ý»º´æµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ