Does somebody know how to cache doctrine2 entities in a zf2 project. I cant find a tutorial or website where this is explained. I cant find any information to start with defining a entity filecache.
Somebody of you got working links or examples.
Thanks
You have two options
Use doctrine's native caching, e.g. using memcache (in the memcache block you can use any kind of doctrine supported cache, a full list of cache drivers is available).
Use doctrine's adapter for Zend/Cache/Storage to use another cache that you're using elsewhere; the adapter is described in the DoctrineModule docs.
As an example of version two, I have something like the following configuration in a module (actually spread across various config files, so I can't guarantee that copy-pasting verbatim will work).
'services' => array(
'factories' => array(
// Wraps a ZF2 cache storage in a Doctrine compatible way
'doctrine.cache.zend.static.local' => function ($services) {
return new ZendStorageCache($services->get('cache.static.local'));
},
),
'caches' => array(
// A ZF2 cache, can be configured as you like
'cache.static.local' => array(
'adapter' => 'xcache',
'plugins' => array(
'exception_handler' => array(
'throw_exceptions' => false,
),
'serializer',
),
),
),
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'zend.static.local',
'query_cache' => 'zend.static.local',
),
),
),
Note that Doctrine annoyingly automatically prefixes "doctrine.cache." to the name of the cache service that you configure, so while we configure "metadata_cache" to "zend.static.local", the actual cache service must be named "doctrine.cache.zend.static.local". Obviously you can call them what you want, but you'll need to add that prefix to whatever you call them.
To activate file cache you just need to add in your module.config.php
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
)
),
)
and it will create cache automatically in data/DoctrineModule/cache folder
here is my full doctrine config for ZF 2.2.4 + Doctrine 2
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Modulename/Entity')
),
'orm_default' => array(
'drivers' => array(
'Modulename\Entity' => 'application_entities'
),
)
),
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
)
),
),
Related
I am using magento2 , but its page load time max than 4s.
have alread config useing varnish .
after config use redis , there are still huge sql query at catalog page ? why ? how to speed up this page ?
redis config is : app/etc/env.php
'cache' => array(
'frontend' => array(
'default' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array(
'server' => '127.0.0.1',
'database' => '0',
'port' => '6379',
),
),
'page_cache' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => array(
'server' => '127.0.0.1',
'port' => '6379',
'database' => '1',
'compress_data' => '0',
),
),
),
),
=======================
catalog page query is :
enter image description here
To enable Magento2 profiler following below steps:
Set environment variable: MAGE_PROFILER = html. Refer to this link.
Enable/Set Magento2 developer mode
php bin/magento deploy:mode:set developer
Clear the cache. OR You can disable the cache for time being.
Open the website in browser incognito(private) window. Browse to the slow webpage & check at the bottom, you will see the profiler stack trace showing calls and time taken.
Actually, I'm using "standard" sessions manager config:
http://framework.zend.com/manual/current/en/modules/zend.session.manager.html
I want to use cache and save my session's data into server's cache (memcached) for improves performances and scalability.
I set php.ini like this (localhost memcached):
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
and it show this error:
Warning: session_start(): Cannot find save handler 'memcached' - session startup failed in C:\Program Files (x86)\xampp\htdocs\Zend-application\vendor\zendframework\zendframework\library\Zend\Session\SessionManager.php on line 98
So, I don't understand how to configure my config/autoload/global.php and module/application/module.php. it's my first time that I want to implement memcached and caching in general. thanks, so much!
I tried to modify module/application/module.php like this:
---add session and cache ---
use Zend\Session\Config\SessionConfig;
use Zend\Session\Container;
use Zend\Cache\StorageFactory;
use Zend\Session\SaveHandler\Cache;
use Zend\Session\SessionManager;
use Zend\Session\Validator\HttpUserAgent;
use Zend\Session\Validator\RemoteAddr;
--- end session and cache ---
public function onBootstrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$this->initSession(array(
'remember_me_seconds' => 180,
'use_cookies' => true,
'cookie_httponly' => true,
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
'phpSaveHandler' => 'memcached',
'savePath' => 'tcp://127.0.0.1',
)
));
}
public function initSession($config)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->getValidatorChain()
->attach(
'session.validate',
array(new HttpUserAgent(), 'isValid')
)
->attach(
'session.validate',
array(new RemoteAddr(), 'isValid')
);
$cache = StorageFactory::factory(array(
'adapter' => array(
'name' => 'memcached',
'options' => array(
'server' => '127.0.0.1',
),
)
));
$saveHandler = new Cache($cache);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
but it shows this error:
Warning: ini_set() expects parameter 2 to be string, array given in C:\Program Files (x86)\xampp\htdocs\Zend-application\vendor\zendframework\zendframework\library\Zend\Session\Config\SessionConfig.php on line 88
Fatal error: Call to undefined method Zend\Stdlib\CallbackHandler::attach() in C:\Program Files (x86)\xampp\htdocs\Zend-application\module\Application\Module.php on line 68
this is my config/autoload/global.php
return array(
'db' => array(
'driver' => 'Pdo_Mysql',
'charset' => 'utf-8',
'dsn' => 'mysql:dbname=mydb;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
'session' => array(
'config' => array(
'class' => 'Zend\Session\Config\SessionConfig',
'options' => array(
'name' => 'zend-application',
),
),
'storage' => 'Zend\Session\Storage\SessionArrayStorage',
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
),
),
);
Hoping it'll help someone, I resolved my issue. I'm working in Win7 enviroment and memcached doesn't work on it! I changed :
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
to
session.save_handler=memcache
session.save_path= "tcp://127.0.0.1:11211"
I restored the "standard" session manager config and memcache works correctly. When I'll transfer the entire site to apache server, I'll change php.ini for using memcached.
http://framework.zend.com/manual/current/en/modules/zend.session.manager.html
This is the code, that I've added to config/main.php in my Yii 1.x application:
'mCache' => array(
'class' => 'system.caching.CMemCache',
'useMemcached'=>true,
'keyPrefix'=>'',
'hashKey'=>false,
'serializer'=>false,
'servers' => array(
array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 10000)
),
),
'session' => array(
'sessionName' => 'PHPSESSID',
'class' => 'CCacheHttpSession',
'autoStart' => true,
'cacheID' => 'mCache',
'cookieMode' => 'only',
'timeout' => 1200
),
What should I do next, to force Yii to use CMemCache, instead of default session storage?
I know this answer is old, but this configuration works
'memcacheConn'=>array(
'class'=>'CMemCache',
'servers'=>array(
array(
'host'=>'172.17.0.1',
'port'=>11211,
//'weight'=>60,
),
),
),
'session' => array(
'class' => 'CCacheHttpSession',
'autoStart' => true,
'cacheID' => 'memcacheConn',
'cookieMode' => 'allow',
'sessionName' => 'MYSSIONNAME',
),
Did you read introduction to CMemCache in Yii 1.x API documentation? I think you didn't. In first paragraphs of this document, you have an example, how to use CMemCache in Yii 1.x.
Change 'class'=>'CCacheHttpSession' into 'class'=>'CMemCache' in your session key of configuration file. And you don't have to register CMemCache as separate component, like you did in your example (mCache). You can configure it directly in session configuration key.
An example from Yii 1.x API documentation:
array
(
'components'=>array
(
'cache'=>array
(
'class'=>'CMemCache',
'servers'=>array
(
array
(
'host'=>'server1',
'port'=>11211,
'weight'=>60,
),
array
(
'host'=>'server2',
'port'=>11211,
'weight'=>40,
)
)
)
)
)
I am already using a number of Google API services, such as Calendar and Google+ profiles, but using the Directory services is proving difficult.
Here is the scope I'm declaring in my local_config - everything has been working until I added the final line...
// Definition of service specific values like scopes, oauth token URLs, etc
'services' => array(
'analytics' => array('scope' => 'https://www.googleapis.com/auth/analytics.readonly'),
'calendar' => array(
'scope' => array(
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
)
),
'books' => array('scope' => 'https://www.googleapis.com/auth/books'),
'latitude' => array(
'scope' => array(
'https://www.googleapis.com/auth/latitude.all.best',
'https://www.googleapis.com/auth/latitude.all.city',
)
),
'moderator' => array('scope' => 'https://www.googleapis.com/auth/moderator'),
'oauth2' => array(
'scope' => array(
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
)
),
'plus' => array('scope' => 'https://www.googleapis.com/auth/plus.login'),
'siteVerification' => array('scope' => 'https://www.googleapis.com/auth/siteverification'),
'tasks' => array('scope' => 'https://www.googleapis.com/auth/tasks'),
'urlshortener' => array('scope' => 'https://www.googleapis.com/auth/urlshortener'),
'directory' => array('scope' => 'https://www.googleapis.com/auth/admin')
I have tried a few different combos, but nothing seems to work - here is the error I'm getting...
Some requested scopes were invalid.
{valid=[https://www.googleapis.com/auth/tasks,
https://www.googleapis.com/auth/calendar, https://www.googleapis.com/auth/calendar.readonly, https://www.googleapis.com/auth/userinfo.profile,
https://www.googleapis.com/auth/userinfo.email], invalid=[https://www.googleapis.com/auth/admin]}
I'm trying to pull Group listings at the moment, but I'll need other Admin sdk features later.
Thanks! Let me know if I need to add any more details.
Admin SDK scopes are listed at:
https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
Hey guys im using the installer in my module to add a new EAV product attribute to the Default attribute set. So far its working great, but there are 2 little things that bother me.
public function getDefaultEntities(){
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'disable_sale' => array(
'group' => 'General',
'label' => 'Disable Sale',
'type' => 'int',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'is_visible_on_front' => true,
'used_in_product_listing' => true,
)
)
)
);
}
I want my attribute set to be visible on product details page and catalog listing per default.
'is_visible_on_front' => true,
'used_in_product_listing' => true,
The problem is that both values are not set to be visible.
What am i doing wrong?
I haven't done this with attributes per-se, but try both 'integers' 1 AND 'string' "1" in your code and see if it works.
is_visible_on_front change to visible_on_front and then check.
Found the answer here at stackoverflow:
Magento module setup/installer script
Setup class should extend from
Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
Now the installer is aware of the additional attributes and its working like a charme.