1

嗨,我有一个带有 php zend 框架的应用程序,我在我的 zend 应用程序上设置了一个 AWS ElastiCache,如下所示

引导程序.php:

protected function _initMemcache()
{
    if (extension_loaded('memcache'))
    {
        // Configure caching backend strategy
        $cacheBackend = new Zend_Cache_Backend_Memcached(
            array(
                'servers' => array(
                    array(
                        'host' => 'xxxx.yyyy.qqq.rrr.cache.amazonaws.com',
                        'port' => '11211'
                    )
                    // Other servers here
                ),
                'compression' => true,
                'compatibility' => true
            )
        );

        // Configure caching frontend strategy
        $cacheFrontend = new Zend_Cache_Core(
            array(
                'caching' => true,
                'cache_id_prefix' => 'MyApp_',
                'write_control' => true,
                'automatic_serialization' => true,
                'ignore_user_abort' => true
            )
        );

        // Build a caching object
        $memcache = Zend_Cache::factory($cacheFrontend, $cacheBackend);

        Zend_Registry::set('cache', $memcache);
    } else {
        // Handle a non-existent extension here
    }
}

在我的控制器上:

public function fetchfrontAction()
{
    $cache = Zend_Registry::get('cache');

    $catid = $this->_getParam('catId');

    $business = new Application_Model_Mapper_BusinessMapper();
    $businessReviewMapper = new Application_Model_Mapper_BusinessReviewsMapper();
    $count = 5;
    if (!$result = $cache->load('dataset')) {

        $result = $business->getFetchByCategory($catid,$count);

        for ($i = 0; $i < count($result); $i++) {

            $result[$i]['business_name_url'] =  $result[$i]['business_url'];
            $userBusinessReviews = $businessReviewMapper->getBusinessReview($result[$i]['business_id'],1);

            if(!is_null($userBusinessReviews)){
                $result[$i]['user_business_reviews'] = $userBusinessReviews;
            }
            $userImg = $this->view->getLoginUserImage(
                $result[$i]['user_business_reviews'][0]['social_id'],
                $result[$i]['user_business_reviews'][0]['login_type'],null,null,square);
            if (!is_null($userImg)) {
                $result[$i]['user_img'] = $userImg;
            }
        }
        $cache->save($result,'dataset');
    }

    $this->_helper->json($result);
}

现在的问题是它没有任何错误,我如何测试它是否真的从 AWS 缓存?有没有一种方法可以比较使用和不使用缓存的时间?谢谢

4

1 回答 1

0

最简单的方法是在and上放置一个else子句来记录缓存命中。if (!$result = $cache->load())Zend_Log

此外,我认为 AWS 为您提供了一些管理控制台来检查/管理缓存的内容/活动。但只是在那个特定的点上大声思考。

于 2013-03-14T04:19:52.687 回答