switch ($modx->event->name) { case 'OnSiteRefresh': //чистим кеш break; case 'OnBeforeSaveWebPageCache': if ($modx->resource->get('cacheable') && $modx->resource->get('published') && $modx->resource->_output != '') { $memcache = new Memcache; $memcache->connect('localhost', 11211); $expire = 50;//время хранения 50с $uri = $modx->resource->get('uri'); $context = $modx->context->get('key'); $key = "$context/$uri"; $output = &$modx->resource->_output; $time = time(); $cacheArray = array('output'=>$output, 'time'=>$time); $tmp_object = $output; $memcache->set($key, $tmp_object, false, $expire); $memcache->close(); break; } }
$memcache = new Memcache; $memcache->connect('localhost', 11211);//подключаемся к memcache $expire = 50;//время хранения 5с кеша $tmp = "<h1>привет</h1>"; $memcache->set('key', $tmp, false, $expire);//записываем по ключу значение в кеш $memcache->close();//закрываем подключение
$memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Не могу подключиться"); $get_result = $memcache->get('key'); echo "Данные из кеша:".$get_result." \n"; $memcache->close();
$output = &$modx->resource->_output; $time = time(); $cacheArray = array('output'=>$output, 'time'=>$time); $tmp_object = $output;
Поменяй на xPDOMemCached и все.
$config_options = array ( "cache_handler" => "cache.xPDOMemCached", );
public function _postProcess() { if ($this->resourceGenerated && $this->getOption('cache_resource', null, true)) { if (is_object($this->resource) && $this->resource instanceof modResource && $this->resource->get('id') && $this->resource->get('cacheable')) { $this->invokeEvent('OnBeforeSaveWebPageCache'); $this->cacheManager->generateResource($this->resource); } } $this->invokeEvent('OnWebPageComplete'); }
<?php switch($modx->event->name){ case 'OnWebPageComplete': $key = "resource/".$modx->resourceIdentifier; $output = & $modx->resource->_output; $modx->cacheManager->set($key, $output); break; default:; }
обработчик менять на файловый, получать страничку и запихивать уже в memcache
и уже nginx выбирать что modx стандартно кеширует!
ну нормал 100 мс...)))
ты только время кеша маленькое выставил… или еще делаешь что то…
$key = md5($key);
perl_set $md5_uri 'sub { use Digest::MD5 qw(md5_hex); my $r = shift; my $args=$r->args; return md5_hex($args); }';
user nginx; worker_processes 1; worker_rlimit_nofile 100000; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; events { worker_connections 1024; use epoll; } http { perl_set <strong>$md5_uri</strong> 'sub { use Digest::MD5 qw(md5_hex); my $r = shift; my $uri=$r->uri; my $args=$r->args; return md5_hex($args); }'; include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_max_body_size 100m; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; gzip on; gzip_static on; gzip_comp_level 5; gzip_min_length 1024; keepalive_timeout 65; gzip_proxied any; gzip_types text/plain text/html text/xml application/xml application/x-javascript text/javascript text/css text/json; gzip_disable "msie6"; charset utf-8; limit_conn_zone $binary_remote_addr zone=addr:10m; # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
upstream backend-test {server unix:/var/run/php5-test.sock;} server { listen 80; server_name test.ru; root /var/www/test/www; access_log /var/log/nginx/test-access.log; error_log /var/log/nginx/test-error.log; index index.php index.html; rewrite_log on; if ($host != 'test.ru' ) { rewrite ^/(.*)$ http://test.ru/$1 permanent; } location ~* ^/core/ { deny all; } location / { try_files $uri $uri/ @rewrite; } location @rewrite { rewrite ^/(.*)$ /index.php?q=$1; } location ~ \.php$ { default_type text/html; set $memcached_key "default/test_<strong>$md5_uri</strong>"; # где test_ это cache_prefix memcached_pass unix:///var/run/memcached/mem.socket; error_page 404 401 405 502 504 = @php; } location @php { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass backend-test; } location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ { access_log off; expires 10d; break; } location ~ /\.ht { deny all; } }