Очистка кэша при использовании xPDOAPCCache

Дано:
  1. 1 сервер,
  2. 2 домена,
  3. MODX 2.2.5,
  4. php-apc
Настройки php-apc:
extension=apc.so
apc.enabled=1
apc.cache_by_default=1
apc.shm_segments=1
apc.shm_size=128M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.max_file_size=1M
apc.stat=1
Проблема:
При очистке кэша через «Сайт -> Обновить сайт» кэш чистится на обоих сайтах.
Используется cache_handler = cache.xPDOAPCCache, установлен cache_prefix = sitename_
Как разделить кэш доменов, чтобы при очистке только нужный очищался?
Denys Butenko
26 ноября 2012, 15:29
modx.pro
2 337
0

Комментарии: 7

Антон Мамрашев
13 июня 2013, 16:53
0
нашли решение этой проблемы? а то я замучился с этим тоже )
    Алексей
    13 июня 2013, 19:04
    0
    все работает, ничего трогать не надо. убери знак подчеркивания только лишь в префиксе
      Антон Мамрашев
      13 июня 2013, 20:16
      0
      проблема есть, что с подчеркиванием что без, причем кеш смешивается именно в контексте админ панели, на самом сайте нормально отрабатывает, но при очистке кеш удаляется на всех сайтах. С cache.xPDOMemCache та же история.
      Алексей
      13 июня 2013, 20:23
      0
      а папку core/cache/ чистил после переключения на APC?
      там вроде с бубном надо плясать, я уже не припомню, но файлы кэша вручную удаляю при работе с APC — ни одну настройку системную нельзя поменять через обычное «очистить кэш сайта» — в принципе, не напрягает.
        Антон Мамрашев
        13 июня 2013, 20:28
        0
        да, чистил, не помогает, видимо нужно лесть в класс обработки кеша…
          Антон Мамрашев
          14 июня 2013, 01:33
          0
          нашел решение проблемы с админ панелью, если вы используете кеширование запросов к базе данных нужно прописать в настройках cache_db_prefix=sitename_ и cache_prefix = sitename_
            Антон Мамрашев
            14 июня 2013, 12:29
            0
            Итак окончательное решение проблемы:
            выставляем в настройках cache_db_prefix=sitename_ и cache_prefix = sitename_
            загружаем в /var/www/nwstroy/www/core/xpdo/cache обновленный класс обработчик кеша

            <?php
            /*
             * Copyright 2010-2013 by MODX, LLC.
             *
             * This file is part of xPDO.
             *
             * xPDO is free software; you can redistribute it and/or modify it under the
             * terms of the GNU General Public License as published by the Free Software
             * Foundation; either version 2 of the License, or (at your option) any later
             * version.
             *
             * xPDO is distributed in the hope that it will be useful, but WITHOUT ANY
             * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
             * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
             *
             * You should have received a copy of the GNU General Public License along with
             * xPDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
             * Suite 330, Boston, MA 02111-1307 USA
             */
            
            /**
             * Provides an APC-powered xPDOCache implementation.
             *
             * This requires the APC extension for PHP, version 3.1.4 or later. Earlier versions
             * did not have all the necessary user cache methods.
             *
             * @package xpdo
             * @subpackage cache
             */
            class xPDOAPCOneFushCache extends xPDOCache
            {
            	public function __construct(& $xpdo, $options = array())
            	{
            		parent :: __construct($xpdo, $options);
            		if (function_exists('apc_exists')) {
            			$this->initialized = true;
            		} else {
            			$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOAPCCache[{$this->key]}: Error creating APC cache provider; xPDOAPCCache requires the APC extension for PHP, version 2.0.0 or later.");
            		}
            	}
            
            	public function add($key, $var, $expire = 0, $options = array())
            	{
            		$added = apc_add(
            			$this->getCacheKey($key),
            			$var,
            			$expire
            		);
            		return $added;
            	}
            
            	public function set($key, $var, $expire = 0, $options = array())
            	{
            		$set = apc_store(
            			$this->getCacheKey($key),
            			$var,
            			$expire
            		);
            		return $set;
            	}
            
            	public function replace($key, $var, $expire = 0, $options = array())
            	{
            		$replaced = false;
            		if (apc_exists($key)) {
            			$replaced = apc_store(
            				$this->getCacheKey($key),
            				$var,
            				$expire
            			);
            		}
            		return $replaced;
            	}
            
            	public function delete($key, $options = array())
            	{
            		$deleted = false;
            		if (!isset($options['multiple_object_delete']) || empty($options['multiple_object_delete'])) {
            			$deleted = apc_delete($this->getCacheKey($key));
            		} elseif (class_exists('APCIterator', true)) {
            			$iterator = new APCIterator('user', '/^' . str_replace('/', '\/', $this->getCacheKey($key)) . '/', APC_ITER_KEY);
            			if ($iterator) {
            				$deleted = apc_delete($iterator);
            			}
            		}
            		return $deleted;
            	}
            
            	public function get($key, $options = array())
            	{
            		$value = apc_fetch($this->getCacheKey($key));
            		return $value;
            	}
            
            	public function flush($options = array())
            	{
            		$flushed = false;
            		if (class_exists('APCIterator', true) && $this->getOption('flush_by_key', $options, true) && !empty($this->key)) {
            			$cache_prefix = $this->getOption('cache_prefix', $options);
            			if (!empty($cache_prefix)) {
            				$iterator = new APCIterator('user', '/^' . str_replace('/', '\/', $this->key) . '\/' . str_replace('/', '\/', $cache_prefix) . '/', APC_ITER_KEY);
            			} else {
            				$iterator = new APCIterator('user', '/^' . str_replace('/', '\/', $this->key) . '\//', APC_ITER_KEY);
            			}
            			if ($iterator) {
            				$flushed = apc_delete($iterator);
            			}
            		} else {
            			$flushed = apc_clear_cache('user');
            		}
            		return $flushed;
            	}
            }


            меняем настройку cache_handler на cache.xPDOAPCOneFushCache
            очищаем папку /var/www/nwstroy/www/core/cache и кеш apc в apc.php

            все, теперь при очистке кеш удаляется только на одном из сайтом, с помощью доработанной функции flush в cache.xPDOAPCOneFushCache
              Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
              7