尊龙凯时人生就是博

laravelÔõôÉè¼Æ»º´æ

Ëæ×ÅwebÓ¦ÓóÌÐòÖØƯºóµÄÒ»Ö±ÔöÌí £¬»º´æµÄʹÓñäµÃÔ½À´Ô½Ö÷Òª¡£ÔÚlaravelÖÐ £¬»º´æÉè¼ÆºÜÊÇÎÞаÇÒÒ×ÓÚʹÓᣱ¾ÎĽ«ÏÈÈÝlaravelÖлº´æµÄ»ù±¾Éè¼ÆÍ·ÄÔ¼°ÆäʹÓÃÒªÁì¡£

Ò»¡¢»º´æÔ­Àí

»º´æÊÇÒ»ÖÖ½«ÅÌËãЧ¹û¡¢ÍøÂçÊý¾Ý»òÆäËûÅÌËã»ú²Ù×÷Ч¹û´æ´¢ÔÚÒ×ÓÚ»á¼ûµÄλÖõÄÊÖÒÕ¡£Óë´ÓԴͷÿһ´Î»ñÈ¡Êý¾ÝÏà±È £¬ÔÚ»º´æÖд洢Êý¾Ý¿ÉÒÔ´ó·ùïÔÌ­»á¼ûÑÓ³ÙºÍЧÀÍÆ÷¸ºÔØ £¬²¢Ê¹¶ÔÊý¾ÝµÄ»á¼û¸ü¿ìËٺ͸üÌñ¾²¡£

LaravelÌṩÁËÐí¶à»º´æÇý¶¯³ÌÐò £¬°üÀ¨Îļþ¡¢Êý¾Ý¿â¡¢RedisºÍMemcachedµÈ £¬ÒÔ±ãÓÚÖÎÀí»ººÍ´æÊý¾Ý¡ £»º´æÇý¶¯³ÌÐòÖÐ×î³£ÓõÄÊÇÎļþºÍRedisÇý¶¯³ÌÐò¡£

µ±ÎÒÃÇÔÚʹÓÃLaravelʱ £¬ÎÒÃÇͨ³ £»áʹÓûº´æÀ´Ìá¸ßÓ¦ÓóÌÐòÐÔÄÜ¡£±ðµÄ £¬»º´æ»¹ÊÊÓÃÓÚ± £»¤WebÓ¦ÓóÌÐòÃâÓÚ¹¥»÷ £¬ÌØÊâÊÇ´ÓDDoS¹¥»÷Öб £»¤ËüÃÇ¡£

¶þ¡¢Ê¹Óûº´æ

ÔÚLaravelÖÐʹÓûº´æºÜÊÇÀû±ã¡ £¿ÉÒÔʹÓûº´æÃÅÃæ(Cache facade)»òʹÓûº´æ¸¨Öúº¯ÊýÀ´´æ´¢ºÍ¼ìË÷Êý¾Ý¡£È·¶¨×¼È·µÄ»º´æÇý¶¯³ÌÐòºÍÑ¡Ôñ׼ȷµÄ»º´æ±êʶ·ûºÜÊÇÖ÷Òª £¬²»È»¿ÉÄܻᱬ·¢ÒâÏë²»µ½µÄЧ¹û¡£

1.ÉèÖûº´æÇý¶¯³ÌÐò

ÔÚLaravelÖÐ £¬»º´æÇý¶¯³ÌÐò¾öÒéÊý¾Ý´æ´¢ÔÚÄÇÀïÒÔ¼°ÄÄÖÖÒªÁìÓÃÓÚ´æ´¢ºÍ¼ìË÷Êý¾Ý¡£Ä¬ÈÏÇéÐÎÏ £¬ÉèÖÃÎļþ´æ´¢ÔÚconfig/cache.phpÖÐ £¬ÆäÖнç˵ÁËĬÈϵĻº´æÇý¶¯³ÌÐòºÍÆäËû¿ÉÓõĻº´æÇý¶¯³ÌÐò¡£

ÈôÊÇÒª¸ü¸ÄĬÈϵĻº´æÇý¶¯³ÌÐò £¬¿ÉÒÔÔÚ.envÖÐÉèÖÃCACHE_DRIVER±äÁ¿¡£Ä¬ÈÏÇéÐÎÏ £¬LaravelʹÓÃÎļþ»º´æ £¬¿ÉÊÇÕâÖÖ»º´æ²»ÊʺϸßÁ÷Á¿Õ¾µã¡£Òò´Ë £¬Redis»º´æÇý¶¯³ÌÐò¿ÉÄÜÊǸüºÃµÄÑ¡Ôñ¡£

2.ʹÓûº´æ

ʹÓûº´æºÜÊǼòÆÓ £¬²¢ÇÒÖ»ÐèÒª¼¸ÐдúÂë¼´¿ÉÍê³É´æ´¢ºÍ¼ìË÷Êý¾ÝµÄÀú³Ì¡£

´æ´¢Êý¾Ý£º

Cache::put('key', 'value', $minutes);

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÁ콫Êý¾Ý´æ´¢ÔÚ»º´æÖÐ £¬²¢Ö¸¶¨»º´æÓâÆÚʱ¼ä £¬ÒÔÃëΪµ¥Î»¡£

ÈôÊÇÒªÓÀÊÀ´æ´¢Êý¾Ý £¬¿ÉÒÔʹÓÃforeverÒªÁ죺

Cache::forever('key', 'value');

µÇ¼ºó¸´ÖÆ

¼ìË÷Êý¾Ý£º

$value = Cache::get('key');

µÇ¼ºó¸´ÖÆ

ÈôÊÇÕÒ²»µ½Ö¸¶¨µÄ»º´æ¼ü £¬Ôò·µ»Ønull¡£

ÁíÍâ £¬»¹¿ÉÒÔʹÓÃhasÒªÁìÀ´¼ì²é»º´æ¼üÊÇ·ñ±£´æ£º

if (Cache::has('key')) {
    //do something
}

µÇ¼ºó¸´ÖÆ

Èý¡¢»º´æ±êʶ·û

ÔÚLaravelÖÐ £¬»º´æ±êʶ·ûÊÇ»º´æµÄÒªº¦¡£Ëüͨ³£ÊÇÒ»¸ö×Ö·û´® £¬ÓÃÓÚÌåÏÖ»º´æÌõÄ¿µÄΨһÐÔ¡£ÔÚÈ·¶¨»º´æ±êʶ·ûʱ £¬Ó¦Ë¼Á¿ÒÔϼ¸µã£º

1.È·±£±êʶ·ûΨһ¡ £»º´æ±êʶ·û±ØÐèÊÇΨһµÄ £¬ÓÉÓÚÈôÊÇÁ½¸ö»ò¶à¸ö»º´æÌõĿʹÓÃÏàͬµÄ±êʶ·û £¬Ôò¿ÉÄܻᵼÖÂÊý¾Ý³åÍ»¡£

2.È·±£±êʶ·û¿É¶ÁÐԺá£Ó¦¸ÃʹÓÃÒ×ÓÚÔĶÁºÍÃ÷È·µÄ»º´æ±êʶ·û¡£

3.ÏÞÖƱêʶ·û³¤¶È¡ £»º´æ±êʶ·ûµÄ³¤¶ÈÓ¦¸Ã×ã¹»¶Ì £¬ÒÔ±ãÓÚ´æ´¢ºÍ¼ìË÷Êý¾Ý¡£¹ØÓڽϳ¤µÄ±êʶ·û £¬¿ÉÒÔ˼Á¿Ê¹ÓùþÏ£Öµ¡£

ËÄ¡¢»º´æÊÃ÷ÈÕ½

ÔÚʹÓûº´æʱ £¬ÎÒÃÇÐèҪ˼Á¿Êý¾ÝµÄʵʱÐÔºÍ׼ȷÐÔÖ®¼äµÄƽºâ¡£ÈôÊÇÎÒÃÇÐèÒª¡°ÐÂÏÊ¡±µÄÊý¾Ý £¬ÄÇôÈÃÊý¾ÝÁ¬Ã¦´ÓÊý¾Ý¿âÖжÁÈ¡ÊÇ×îºÃµÄ²½·¥¡£¿ÉÊÇ £¬ÈôÊÇÎÒÃÇÐèÒª´¦Àí´ó×ÚÇëÇó £¬Ôòÿ´Î¶¼´ÓÊý¾Ý¿âÖжÁÈ¡Êý¾Ý»á¼«´óµØÓ°ÏìWebÓ¦ÓóÌÐòµÄÐÔÄÜ¡£

Òò´Ë £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÏÞÖÆ»º´æ¼üµÄÓâÆÚʱ¼äÀ´Æ½ºâÐÔÄܺÍÊý¾Ý׼ȷÐÔ¡£LaravelÔÊÐíÎÒÃÇÔÚÊý¾Ý±ä»»Ê±É¾³ý»º´æ¼ü¡£µ±Ï´ÎÇëÇóµ½À´Ê± £¬½«ÖØн¨É軺´æ¼ü £¬²¢ÖØÐÂÉúÑÄÊý¾Ý £¬ÒÔ±ãÓÚÓ¦ÓóÌÐòµÄÏÂÒ»²½Ê¹Óá£

ÈçÏÂÊÇÒ»¸öʹÓûº´æµÄÀý×Ó£º

public function getUsers()
{
    $key = 'users';
    $minutes = 60;
    $users = Cache::remember($key, $minutes, function () {
        return DB::table('users')->get();
    });
    return $users;
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃǽ«¼ì²éÊÇ·ñ±£´æÓëusers»º´æ¼ü¶ÔÓ¦µÄÖµ¡£ÈôÊDZ£´æ £¬Ôò½«·µ»Ø¸ÃÖµ¡£ÈôÊÇ»º´æ¼ü²»¿ÉÓà £¬Ôò½«´ÓÊý¾Ý¿âÖлñÈ¡Óû§ÁÐ±í²¢½«Æ仺´æ¡£

ÈôÊÇÎÒÃÇÐèҪǿÖÆˢлº´æ £¬¿ÉÒÔʹÓÃforgetÒªÁ죺

Cache::forget('users');

µÇ¼ºó¸´ÖÆ

Õâ»á´Ó»º´æÖÐɾ³ýÖ¸¶¨µÄ»º´æ¼ü¡£

ÁíÍâ £¬ÎÒÃÇ¿ÉÒÔʹÓÃCache facade»ò»º´æ¸¨Öúº¯ÊýÀ´ÉèÖûº´æ±êʶ·û»ººÍ´æʱ¼ä¡£

Îå¡¢½áÂÛ

»º´æÊÇWebÓ¦ÓóÌÐò´¦ÀíÊý¾ÝµÄÖ÷Òª²¿·Ö¡£LaravelÌṩÁËÒ»¸öÎÞаµÄ»º´æϵͳ £¬¿ÉÒÔ×ÊÖúÎÒÃǸüÓÐÓõش¦ÀíÊý¾Ý £¬²¢Ìá¸ßWebÓ¦ÓóÌÐòµÄÐÔÄÜ¡£Í¨¹ý׼ȷµØʹÓûº´æ±êʶ·û»ººÍ´æÇý¶¯³ÌÐò £¬ÎÒÃÇ¿ÉÒÔÇáËɵØʵÏÖ¿ÉÉìËõÐԺͿÉÀ©Õ¹ÐÔ¡£

ÔÚʹÓûº´æʱ £¬ÐèҪעÖØ׼ȷµÄƽºâÐÔÄܺÍÊý¾Ý׼ȷÐÔÖ®¼äµÄ¹Øϵ¡£Í¨¹ýÊÊÍâµØÑ¡Ôñ»º´æ¼üµÄÓâÆÚʱ¼äºÍɾ³ýÎÞÓûº´æÊý¾Ý £¬ÎÒÃÇ¿ÉÒÔʵÏÖ¸ü¸ßЧµÄWebÓ¦ÓóÌÐò¡£

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

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

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

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