尊龙凯时人生就是搏

Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel CacheʵÏÖ»º´æ £¿

laravel¿ª·¢£ºÔõÑùʹÓÃlaravel cacheʵÏÖ»º´æ £¿

Ëæ×ÅWebÓ¦ÓóÌÐòµÄÉú³¤£¬ÐÔÄÜÎÊÌâÒѾ­³ÉΪÏÖ´úWebÓ¦ÓóÌÐòµÄÒªº¦ÎÊÌ⡣ʹÓûº´æÊǽâ¾öWebÓ¦ÓóÌÐòÐÔÄÜÎÊÌâµÄÒ»ÖÖ³£¼ûÒªÁì¡£LaravelÌṩÁËÒ»ÖÖÎÞаµÄ»º´æ½â¾ö¼Æ»®£¬³ÆΪ»º´æ¡£»º´æÊÇÒ»ÖÖ½«Êý¾Ý´æ´¢ÔÚÔÝʱ´æ´¢ÖеÄÊÖÒÕ£¬ÒÔ±ãÒÔºó¿ÉÒÔ¸ü¿ìµØ¼ìË÷ºÍÏÔʾÊý¾Ý¡£±¾ÎĽ«Ì½ÌÖLaravel»º´æÔõÑùʵÏÖºÍʹÓá£

Laravel Cache¼ò½é

Laravel CacheÌṩÁËÒ»ÖÖͳһµÄAPIÀ´Ê¹ÓÃÖÖÖÖ»º´æºó¶Ë£¨ÈçMemcached£¬RedisºÍÎļþ»º´æ£©¡£ÓÉÓÚLaravel CacheÊÇLaravelµÄ×é¼þÖ®Ò»£¬Òò´Ë¿ÉÒÔʹ»º´æ±äµÃÔ½·¢ÈÝÒ׺ÍÀû±ã¡£Laravel Cache¿ÉÒÔÔÚÓ¦ÓóÌÐòÖеÄÈκεط½Ê¹Óã¬ÒÔÌá¸ßÓ¦ÓóÌÐòµÄÐÔÄÜ¡£

Laravel CacheÉèÖÃ

Laravel CacheµÄĬÈϺó¶ËÊÇÎļþÇý¶¯¡£¿ÉÊÇ£¬ÎÒÃÇ¿ÉÒÔÇáËɵØÔÚconfig / cache.phpÎļþÖиü¸Ä»º´æºó¶Ë¡£ÀýÈ磬ҪʹÓÃMemcached»º´æºó¶Ë£¬¿ÉÒÔÔÚconfig / cache.phpÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺

‘cache’ => [

'default' => env('CACHE_DRIVER', 'memcached'),

'stores' => [
    'memcached' => [
        'driver' => 'memcached',
        'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
        'sasl' => [
            env('MEMCACHED_USERNAME'),
            env('MEMCACHED_PASSWORD'),
        ],
        'options' => [
            // Memcached::OPT_CONNECT_TIMEOUT  => 2000,
        ],
        'servers' => [
            [
                'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                'port' => env('MEMCACHED_PORT', 11211),
                'weight' => env('MEMCACHED_WEIGHT', 100),
            ],
        ],
    ],

    // ...
],

// ...

µÇ¼ºó¸´ÖÆ

],

Õâ¸öʾÀý´úÂëÖУ¬ÎÒÃÇʹÓÃÁËMemcached»º´æºó¶Ë¡£

Laravel CacheʹÓÃ

ÔÚLaravelÓ¦ÓóÌÐòÖÐʹÓûº´æÊǺÜÊÇÈÝÒ׵ġ£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£¬ËµÃ÷ÎúÔõÑù½«Êý¾Ý´æ´¢ÔÚ»º´æÖУº

// ´æ´¢Êý¾Ý

Cache::put(‘key’, ‘value’, $minutes);

// »ñÈ¡Êý¾Ý

$value = Cache::get(‘key’);

// ÅжÏÊý¾ÝÊÇ·ñ±£´æ

if (Cache::has(‘key’)) {

//

µÇ¼ºó¸´ÖÆ

}

// ɾ³ýÊý¾Ý

Cache::forget(‘key’);

Õâ¸öʾÀý´úÂëÖУ¬Cache::put£¨£©ÒªÁ콫Êý¾Ý´æ´¢ÔÚ»º´æÖУ¬Cache::get£¨£©ÒªÁì´Ó»º´æÖмìË÷Êý¾Ý£¬Cache::has£¨£©ÒªÁì¼ì²éÊý¾ÝÊÇ·ñ±£´æ£¬Cache::forget£¨£©ÒªÁì´Ó»º´æÖÐɾ³ýÊý¾Ý¡£

»º´æ±êÇ©

»º´æ±êÇ©ÊÇÒ»ÖÖ½«¶à¸ö»º´æÏî×éÖ¯µ½Ò»ÆðµÄ»úÖÆ¡£Ê¹Óûº´æ±êÇ©ºÜÈÝÒ×ʶ±ð²¢É¨³ý»º´æ¡£ÏÂÃæÊÇÒ»¸ö˵Ã÷ÔõÑùʹÓûº´æ±êÇ©µÄʾÀý£º

// ½«Êý¾Ý´æ´¢µ½»º´æ±êÇ©ÖÐ

Cache::tags([‘people’, ‘artists’])->put(‘John’, $john, $minutes);

Cache::tags([‘people’, ‘authors’])->put(‘Anne’, $anne, $minutes);

// ÕûÀí»º´æ±êÇ©Êý¾Ý

Cache::tags(‘people’)->flush();

Õâ¸öʾÀý´úÂëÖУ¬ÎÒÃÇʹÓÃÁË»º´æ±êÇ©½«Êý¾Ý×éÖ¯ÔÚÒ»Æð¡£Ê¹ÓÃCache::tags£¨£©ÒªÁìÖ¸¶¨»º´æ±êÇ©£¬È»ºó¿ÉÒÔʹÓÃput£¨£©½«Êý¾Ý´æ´¢ÔÚ±êÇ©ÖС£×îºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃflush£¨£©ÒªÁìɨ³ýÓë±êÇ©¹ØÁªµÄËùÓлº´æ¡£

»º´æÓÐÓÃÆÚ

Laravel CacheÌṩÁËÐí¶à²î±ðµÄÒªÁìÀ´ÉèÖûº´æµÄÓÐÓÃÆÚ¡£×î³£ÓõÄÒªÁìÊÇʹÓÃput£¨£©ÒªÁìÖеÄ$ minutesÊôÐÔ¡£ÀýÈ磬Ҫ½«»º´æÏî´æ´¢Îª10·ÖÖÓ£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

// ´æ´¢10·ÖÖÓ»º´æ

Cache::put(‘key’, ‘value’, 10);

// ´æ´¢ÓÀÊÀ»º´æ

Cache::forever(‘key’, ‘value’);

// ¼ìË÷Öµ²¢ÖØд洢Ëü

$value = Cache::remember(‘users’, $minutes, function () {

return DB::table('users')->get();

µÇ¼ºó¸´ÖÆ

});

Õâ¸öʾÀý´úÂëÖУ¬Cache::put£¨£©ÒªÁ콫Êý¾Ý´æ´¢ÔÚ»º´æÖУ¬¿ÉÊÇ»º´æ½ö±£´æ10·ÖÖÓ¡£Cache::forever£¨£©ÒªÁ콫Êý¾Ý´æ´¢ÔÚ»º´æÖУ¬µ«²»ÉèÖõ½ÆÚʱ¼ä¡£Cache::remember£¨£©ÒªÁ콫ÔÚ»º´æÖвéÕÒ¡°users¡±Ïî¡£ÈôÊǸÃÏî²»±£´æ£¬ÔòŲÓûص÷º¯Êý²¢½«Æä·ÅÈ뻺´æÖС£×ÝÈ»»º´æÓâÆÚ£¬Ò²½«Ê¹Óûº´æµÄÊý¾Ý¡£

½áÂÛ

Laravel CacheÊÇÒ»¸öÇ¿Ê¢µÄ»º´æ½â¾ö¼Æ»®£¬¿ÉÒÔ×ÊÖúÌá¸ßWebÓ¦ÓóÌÐòµÄÐÔÄÜ¡£±¾ÎÄÏÈÈÝÁËLaravel CacheµÄ¿´·¨ºÍÓ÷¨£¬²¢ÌṩÁËʾÀý´úÂëÀ´×ÊÖú¶ÁÕßÏàʶÔõÑùʹÓÃLaravel CacheʵÏÖ»º´æ¡£Í¨¹ýʹÓÃLaravel Cache£¬¿ª·¢Ö°Ô±¿ÉÒÔ´ó´óÌá¸ßWebÓ¦ÓóÌÐòµÄÐÔÄÜ£¬²¢Ìṩ¸üºÃµÄÓû§ÌåÑé¡£

ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel CacheʵÏÖ»º´æ £¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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