dousuie2222 2014-01-26 22:23
浏览 57
已采纳

跨会话缓存

Is there any cross(-user)-session cache mechanism?

The problem is:

  • I'm building a Magento module (Magento+Zend on Linux) which frequently triggers SOAP queries;
  • Some of those queries are just to request the sessionID, so it could be saved with a timeout control (considering each sessionID lasts for one hour)
  • Those sessionId's are related to server-to-server communication; There's no relation with the current user session (backup operation, for example). That said, I'm not concerned about one impersonate another;

I've heard several bad things/posts about APC - so I'm putting it away. Let me know if you have any good argument to let re-consider it as an option.

MemCached looks a good alternative, since it looks like there's some sort of lib already implemented inside Zend to deal with it.

Basically, I'm concerned about reducing this sessionId requests.

Thanks a lot!

UPDATE

The answer bellow didn't actually solved the problem but comments did it. Zend_Cache (as mentioned by @Rijndael) is the solution to my situation. The final code should be very similar to this:

$frontendOptions = array(
   'lifetime' => 7200, // cache lifetime of 2 hours
   'automatic_serialization' => true
);

$backendOptions = array(
    'cache_dir' => './tmp/' // Directory where to put the cache files
);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core',
                             'File',
                             $frontendOptions,
                             $backendOptions);

if( ($result = $cache->load('myresult')) === false ) {

    // cache miss; connect to the database 
    $db = Zend_Db::factory( [...] );
    $result = $db->fetchAll('SELECT * FROM huge_table');
    $cache->save($result, 'myresult');
} else {
    // cache hit! shout so that we know
    echo "This one is from cache!

";
}
print_r($result);

http://framework.zend.com/manual/1.12/en/zend.cache.introduction.html

  • 写回答

1条回答 默认 最新

  • doubiaozhan0745 2014-01-28 01:25
    关注

    Not sure about the specifics of magento but as a ZF developer there are several ways you can approach this:

    If by cross-session you are referring to an application that exists on the same server but under a different subdomain, you could do something like:

    In application.ini:

    session.domaincookie = .mysite.co.uk ; 
    

    Then in bootstrap,

    Zend_Session::setOptions($this->getOption('session'));
    

    The above approach will make session data visible across ALL subdomains.

    If it is a 3rd party API then just store the sessionId in the local session:

    $s = new Zend_Session_Namespace("user_session");
    $s->session_id = $api->session_id;
    $s->setExpirationSeconds(strtotime("+1 hour"));
    

    Don't use APC, it is a deserted project. If you need memory caching, using Redis or Memcached. You can also use Zend_Cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器