×ðÁú¿­Ê±

thinkphp6»º´æʱ¼äÉèÖÃ

thinkphp6ÊÇÒ»¸ö¸ßЧ¡¢¾«Á·¡¢ÎÞаµÄphpºǫ́¿ª·¢¿ò¼Ü¡£ÔÚ¿ª·¢Àú³ÌÖÐ £¬ÎªÁËÌá¸ßÍøÕ¾µÄÐÔÄܺÍÓû§ÌåÑé £¬ÎÒÃǾ­³£ÐèҪʹÓûº´æÊÖÒÕ¡£È»¶ø £¬»º´æµÄÓÐÓÃÏÞÆÚÒ»µ©ÓâÆÚ £¬¾Í»áÓ°ÏìÍøÕ¾µÄÐÔÄÜ¡£Òò´Ë £¬ÉèÖûº´æʱ¼äÊǺÜÊÇÖ÷ÒªµÄ¡£

ThinkPHP6¿ò¼ÜÌṩÁ˶àÖÖ»º´æÇý¶¯ £¬°üÀ¨Îļþ»º´æ¡¢Redis»º´æ¡¢Memcached»º´æµÈ¡£ÕâƪÎÄÕ½«Ö÷ÒªÏÈÈÝÔõÑùÉèÖÃÎļþ»º´æºÍRedis»º´æµÄ»º´æʱ¼ä¡£

Ò»¡¢Îļþ»º´æµÄ»º´æʱ¼äÉèÖÃ

ÔÚÉèÖÃÎļþ(config/cache.php)ÖÐ £¬¿ÉÒÔ¶Ô²î±ðµÄ»º´æÇý¶¯ÉèÖÃĬÈϵĻº´æʱ¼ä¡£

return [

    // ĬÈÏ»º´æÇý¶¯
    'default' => env('cache.driver', 'file'),

    // »º´æÅþÁ¬ÉèÖã¨Æ¾Ö¤»º´æÇý¶¯Ñ¡ÔñÉèÖã©
    'stores'  => [
        'file' => [
            'driver' => 'file',
            'cache_subdir' => true,
            'prefix' => '',
            'path' => env('runtime_path') . 'cache',
            'expire' => 3600, // ĬÈÏ»º´æʱ¼ä1Сʱ
        ],
        // ...
    ],
];

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬’expire’Ñ¡ÏîÉèÖÃÁËÎļþ»º´æµÄĬÈÏ»º´æʱ¼äΪ1Сʱ¡£ÈôÊÇÐèÒªÉèÖòî±ðµÄ»º´æʱ¼ä £¬¿ÉÒÔÔÚʹÓûº´æʱ¾ÙÐÐÉèÖà £¬ÀýÈ磺

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

// ÉèÖûº´æÓÐÓÃÆÚΪ10·ÖÖÓ
Cache::store('file')->set('key', 'value', 600);

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬set()ÒªÁìµÄµÚÈý¸ö²ÎÊýÉèÖÃÁË»º´æʱ¼äΪ600Ãë £¬¼´10·ÖÖÓ¡£

¶þ¡¢Redis»º´æµÄ»º´æʱ¼äÉèÖÃ

Redis»º´æµÄ»º´æʱ¼ä¿ÉÒÔÔÚÉèÖÃÎļþ(config/cache.php)ÖоÙÐÐÉèÖà £¬ÀýÈ磺

return [

    // ĬÈÏ»º´æÇý¶¯
    'default' => env('cache.driver', 'redis'),

    // »º´æÅþÁ¬ÉèÖã¨Æ¾Ö¤»º´æÇý¶¯Ñ¡ÔñÉèÖã©
    'stores'  => [
        'redis' => [
            'driver' => 'redis',
            'connection' => 'cache',
            'prefix' => '',
            'expire' => 3600, // ĬÈÏ»º´æʱ¼ä1Сʱ
        ],
        // ...
    ],
];

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬’expire’Ñ¡ÏîÉèÖÃÁËRedis»º´æµÄĬÈÏ»º´æʱ¼äΪ1Сʱ¡£ÔÚÏÖʵʹÓÃÖÐ £¬¿ÉÒÔͨ¹ýÒÔÏ´úÂëÉèÖûº´æʱ¼ä£º

// ÉèÖûº´æÓÐÓÃÆÚΪ10·ÖÖÓ
Cache::store('redis')->set('key', 'value', 600);

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬set()ÒªÁìµÄµÚÈý¸ö²ÎÊýÉèÖÃÁË»º´æʱ¼äΪ600Ãë £¬¼´10·ÖÖÓ¡£

Èý¡¢»º´æÇý¶¯×Ô½ç˵»º´æʱ¼ä

³ýÁËÔÚÉèÖÃÎļþÖÐÉèÖÃĬÈϵĻº´æʱ¼ä £¬ÎÒÃÇ»¹¿ÉÒÔÔÚʹÓûº´æʱ×Ô½ç˵»º´æʱ¼ä¡£ÀýÈç £¬Ê¹ÓÃÎļþ»º´æʱ£º

// ÉèÖûº´æÓÐÓÃÆÚΪ10·ÖÖÓ
Cache::store('file')->put('key', 'value', now()->addMinutes(10));

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬put()ÒªÁìµÄµÚÈý¸ö²ÎÊýÉèÖÃÁË»º´æʱ¼äΪ10·ÖÖÓ¡£

×ܽá

ÔÚThinkPHP6¿ò¼ÜµÄ»º´æ²Ù×÷ÖÐ £¬ÉèÖûº´æʱ¼äÊǺÜÊÇÖ÷ÒªµÄ¡ £¿ÉÒÔÔÚÉèÖÃÎļþÖÐÉèÖÃĬÈϵĻº´æʱ¼ä £¬Ò²¿ÉÒÔÔÚʹÓûº´æʱ×Ô½ç˵»º´æʱ¼ä¡£ºÏÀíµØÉèÖûº´æʱ¼ä¿ÉÒÔÔÚÒ»¶¨Ë®Æ½ÉÏÌá¸ßÍøÕ¾ÐÔÄܺÍÓû§ÌåÑé¡£

ÒÔÉϾÍÊÇthinkphp6»º´æʱ¼äÉèÖõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿