2015-04-22 16 views
0

我在共享主機上使用了doctrine2的APC緩存。如何在共享主機的情況下爲不同的URL分離APC緩存?

我承載了同一個項目的幾個實例,但版本不同。所以我不希望他們共享相同的緩存。

,比如我有以下託管網址:

http://phpdemo.******.com:9040/ilook/qa 
http://phpdemo.******.com:9040/ilook/android 
http://phpdemo.******.com:9040/ilook/dev 
http://phpdemo.******.com:9040/ilook/client 

有沒有什麼辦法來區分他們的緩存?

php.ini設置:

[APC] 
apc.shm_size = '128M' 
apc.enabled=1 
apc.shm_segments=1 
apc.num_files_hint=0 
apc.user_entries_hint=0 
apc.ttl=0 
apc.user_ttl=7200 
apc.gc_ttl=3600 
apc.stat=1 
apc.enable_cli=0 
apc.file_update_protection=2 
apc.max_file_size=2M 
apc.cache_by_default=1 
apc.use_request_time=1 
apc.slam_defense=0 
apc.stat_ctime=0 
apc.canonicalize=1 
apc.write_lock=1 
apc.report_autofilter=0 
apc.rfc1867=0 
apc.rfc1867_prefix =upload_ 
apc.rfc1867_name=APC_UPLOAD_PROGRESS 
apc.rfc1867_freq=0 
apc.rfc1867_ttl=3600 
apc.lazy_classes=0 
apc.lazy_functions=0 

正如我使用ZF1 + Doctrine2,所以下面是我在bootstrap.php中文件中使用的配置線。

$config = new \Doctrine\ORM\Configuration(); 

$cache = new \Doctrine\Common\Cache\ApcCache; 

$config->setMetadataCacheImpl($cache); 
$config->setQueryCacheImpl($cache); 
$config->setResultCacheImpl($cache); 
+0

你應該嘗試通過該項目的名稱,即QA前綴緩存,android,dev或客戶端。你是否在框架中使用Doctrine2?如果是的哪一個? – j0k

+0

是的,我正在使用zend framework1的doctrine2。我在我的問題的bootstrap.php文件中添加了APC緩存的配置。 –

+1

您是否嘗試定義與該項目相關的自定義名稱空間?在你的bootstrap.php裏面,'$ cache-> setNamespace('project_name');'([see](https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/ CacheProvider.php#L36-L61)) – j0k

回答

0

關於你bootstrap.php,你應該能夠定義不同的命名空間,以每個項目的緩存,如:

$config = new \Doctrine\ORM\Configuration(); 

$cache = new \Doctrine\Common\Cache\ApcCache; 

// define the cache for this project only 
$cache->setNamespace('project_name'); 

$config->setMetadataCacheImpl($cache); 
$config->setQueryCacheImpl($cache); 
$config->setResultCacheImpl($cache);