×ðÁú¿­Ê±

thinkphp½Ó¿ÚÔõô»º´æ

˼Ë÷ÃÅ¿òphp¿ò¼ÜÒѳÉΪÖڶ࿪·¢ÕßµÄÊ×Ñ¡¿ò¼ÜÖ®Ò» £¬Æä²»µ«¾ßÓиßЧºÍÒ×ÓÃÐÔ £¬²¢ÇÒ»¹Ö§³ÖÖÖÖÖ»º´æÇý¶¯Æ÷ £¬°üÀ¨Îļþ»º´æ¡¢memcached¡¢redisµÈ¡£ÔÚ±¾ÎÄÖÐ £¬ÎÒÃǽ«ÌÖÂÛÔõÑùÔÚthinkphpÓ¦ÓóÌÐòÖÐʹÓûº´æÀ´Ìá¸ßЧÂÊ¡£

ThinkPHP»º´æÏÈÈÝ

ThinkPHP¿ò¼ÜÌṩÁËÒ»¸öͳһµÄ»º´æ²Ù×÷½Ó¿Ú £¬¿ª·¢Õß¿ÉÒÔʹÓÃÖÖÖÖ»º´æÇý¶¯Æ÷À´ÖÎÀíºÍ¿ØÖÆÊý¾ÝµÄ»º´æ¡£»º´æ¿ÉÒÔ´æ´¢ÈκÎÀàÐ͵ÄÊý¾Ý £¬ÀýÈç×Ö·û´®¡¢Êý×é¡¢¹¤¾ßµÈ¡£ÓÉÓÚ»º´æÊǽ«Êý¾Ý´æ´¢ÔÚÄÚ´æÖÐ £¬Òò´Ë¿ÉÒÔÏÔÖø½µµÍÊý¾Ý¿âµÄ¸ºÔز¢Ìá¸ßÓ¦ÓóÌÐòµÄÏìÓ¦ËÙÂÊ¡£

Îļþ»º´æ

Îļþ»º´æÊÇThinkPHP¿ò¼ÜĬÈÏÌṩµÄÒ»ÖÖ»º´æÇý¶¯Æ÷¡£Ëü½«»º´æÊý¾Ý´æ´¢ÔÚÍâµØÎļþϵͳÖÐ £¬ÕâЩÎļþ¿ÉÒÔÔÚ»º´æÓâÆÚºó×Ô¶¯É¾³ý¡£ÒªÊ¹ÓÃÎļþ»º´æ £¬ÐèÒªÔÚÓ¦ÓóÌÐòÉèÖÃÎļþÖÐÉèÖûº´æÉèÖãº

'cache' => [
    // ĬÈÏÇý¶¯Æ÷ΪÎļþ»º´æ
    'default' => 'file',
    // Îļþ»º´æÉèÖÃ
    'stores' => [
        'file' => [
            'type' => 'File',
            'path' => APP_PATH . 'runtime/cache/',
        ],
    ],
],

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÉèÖÃÖÐ £¬ÎÒÃǽ«Ä¬ÈÏ»º´æÇý¶¯Æ÷ÉèÖÃΪÎļþ»º´æ £¬²¢½«»º´æÊý¾ÝµÄ´æ´¢Â·¾¶ÉèÖÃΪ./runtime/cache/Ŀ¼¡£

ÒªÔÚÓ¦ÓóÌÐòÖÐʹÓûº´æ £¬ÎÒÃÇ¿ÉÒÔʹÓÃCacheÀࣺ

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

use thinkacadeCache;

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

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

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

µÇ¼ºó¸´ÖÆ

Memcached»º´æ

MemcachedÊÇÒ»ÖÖ¸ßÐÔÄÜ¡¢ÂþÑÜʽÄڴ湤¾ß»º´æϵͳ £¬ÆÕ±éÓ¦ÓÃÓÚWebÓ¦ÓóÌÐòÖС£ÔÚThinkPHP¿ò¼ÜÖÐ £¬ÎÒÃÇ¿ÉÒÔÇáËɵØʹÓÃMemcached»º´æÇý¶¯Æ÷À´ÖÎÀí»º´æÊý¾Ý¡£ÒªÊ¹ÓÃMemcached»º´æ £¬ÇëÈ·±£ÒѾ­×°Öò¢Æô¶¯ÁËMemcachedЧÀÍ¡£

'cache' => [
    // ĬÈÏÇý¶¯Æ÷ΪMemcached»º´æ
    'default' => 'memcached',
    // Memcached»º´æÉèÖÃ
    'stores' => [
        'memcached' => [
            'type'   => 'Memcached',
            'host'   => '127.0.0.1',
            'port'   => 11211,
            'expire' => 3600,
            'prefix' => '',
        ],
    ],
],

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÉèÖÃÖÐ £¬ÎÒÃǽ«Ä¬ÈÏ»º´æÇý¶¯Æ÷ÉèÖÃΪMemcached £¬²¢½«»º´æÊý¾ÝµÄÓâÆÚʱ¼äÉèÖÃΪ3600Ãë¡£

ÈôÊÇÒªÔÚÓ¦ÓóÌÐòÖÐʹÓûº´æ £¬ÎÒÃÇ¿ÉÒÔʹÓÃCacheÀࣺ

use thinkacadeCache;

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

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

// ɾ³ý»º´æ
Cache::store('memcached')->delete('key');

µÇ¼ºó¸´ÖÆ

Redis»º´æ

RedisÊÇÆÕ±éÓÃÓÚ»º´æºÍÐÂÎÅÐÐÁеĿªÔ´ÄÚ´æÊý¾Ý½á¹¹´æ´¢¡£ÔÚThinkPHP¿ò¼ÜÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃRedis»º´æÇý¶¯³ÌÐòÀ´ÖÎÀíºÍ¿ØÖÆ»º´æÊý¾Ý¡£

'cache' => [
    // ĬÈÏÇý¶¯Æ÷ΪRedis»º´æ
    'default' => 'redis',
    // Redis»º´æÉèÖÃ
    'stores' => [
        'redis' => [
            'type' => 'redis',
            'host' => '127.0.0.1',
            'port' => 6379,
            'password' => '',
            'select' => 0,
            'timeout' => 0,
            'expire' => 3600,
            'persistent' => false,
            'prefix' => '',
        ],
    ],
],

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÉèÖÃÖÐ £¬ÎÒÃǽ«Ä¬ÈÏ»º´æÇý¶¯Æ÷ÉèÖÃΪRedis £¬²¢Ö¸¶¨ÁËRedisЧÀÍÆ÷µÄλÖúͶ˿ںÅ¡£

ÒªÔÚÓ¦ÓóÌÐòÖÐʹÓÃRedis»º´æ £¬ÎÒÃÇ¿ÉÒÔʹÓÃCacheÀࣺ

use thinkacadeCache;

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

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

// ɾ³ý»º´æ
Cache::store('redis')->delete('key');

µÇ¼ºó¸´ÖÆ

»º´æ±ê¼Ç

»º´æ±ê¼ÇÊÇÒ»ÖÖÔÚ»º´æÊý¾ÝÖи½¼Ó±ê¼ÇµÄÒªÁì £¬Ê¹ÎÒÃÇ¿ÉÒÔ¶Ô²î±ðµÄ»º´æÊý¾Ý¾ÙÐÐÇø·ÖºÍ·ÖÀà¡£ÔÚThinkPHP¿ò¼ÜÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓûº´æ±ê¼ÇÀ´¶Ô²î±ðµÄ»º´æÊý¾Ý¾ÙÐÐÖÎÀíºÍ¿ØÖÆ¡£

use thinkacadeCache;

// ÉèÖûº´æ£¬Í¬Ê±Ìí¼Ó»º´æ±ê¼Ç
Cache::store('file')->tag('tag1')->set('key1', 'value1', 3600);

// ƾ֤±ê¼Ç»ñÈ¡»º´æ
$data = Cache::store('file')->tag('tag1')->get('key1');

// ƾ֤±ê¼Çɾ³ý»º´æ
Cache::store('file')->tag('tag1')->clear();

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇʹÓÃÁËÎļþ»º´æÇý¶¯Æ÷ £¬²¢Ê¹Óñê¼Çtag1¶Ô»º´æÊý¾Ý¾ÙÐÐÁË·ÖÀà¡£ÎÒÃÇ¿ÉÒÔʹÓÃCacheÀàµÄtag()ÒªÁìÀ´¶Ô»º´æ¾ÙÐбê¼Ç²Ù×÷¡£

×ܽá

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÌÖÂÛÁËÔõÑùÔÚThinkPHPÓ¦ÓóÌÐòÖÐʹÓûº´æÀ´¼ÓËÙÏìÓ¦ËÙÂÊ¡£ÎÒÃÇÏÈÈÝÁ˼¸ÖÖ³£¼ûµÄ»º´æÇý¶¯Æ÷ £¬°üÀ¨Îļþ»º´æ¡¢MemcachedºÍRedis¡£ÎÒÃÇ»¹Ìáµ½ÁËʹÓûº´æ±ê¼Ç¶Ô»º´æÊý¾Ý¾ÙÐзÖÀàºÍÖÎÀíµÄÖ÷ÒªÐÔ¡£Í¨¹ýʹÓûº´æ £¬ÎÒÃÇ¿ÉÒÔÌá¸ßÓ¦ÓóÌÐòµÄÐÔÄܺÍÏìÓ¦ËÙÂÊ £¬Í¬Ê±½µµÍÊý¾Ý¿â¸ºÔØ¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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