Flush default cache - memcached

I am using a couchbase memcached bucket for my cakephp default cache. I would like to be able to flush the cache when I change the schema within my cakephp app. There is a method to clear the cache however it is asking for arguments.
How do I use this method to clear / flush the cache?
Edit: my bootstrap contains the setup for the cache config
Cache::config('default', array(
'engine' => 'Memcache',
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array(
'127.0.0.1:11211' // localhost, default port 11211
), //[optional]
'duration' => 7200,
'serialize' => false,
'persistent' => true, // [optional] set this to false for non-persistent connections
'compress' => false,
'probability' => 100
)
);

Cache::clear(false, 'default'); // Default configuration, shortcut Cache::clear()
Cache::clear(false, '_cake_core_'); // General framework caching
Cache::clear(false, '_cake_model_'); // Cache for model and datasource caches

Related

external distributed memcache not workking

this is my first post on here.
I installed the latest version of Nextcloud (19.0.0) on one machine and try to split all the services to different vm's. that means DB (mariadb), Storage, redis (for file locking), memcached (distributed cache) on different machines, all of which are running Ubuntu 20.04 LTS. This setup is a bit janky, but it helps me better understand, how each service functions. The DB-Server and Redis are working fine. Now I want to get memcached to work. as soon as i add the parameters i get an internal server error. this is what I have in my config.php
array (
0 => '10.10.10.45',
1 => 'nextcloudtest.test.lan',
),
'datadirectory' => '/nextcloud-data',
'dbtype' => 'mysql',
'version' => '19.0.0.12',
'overwrite.cli.url' => 'https://nextcloudtest.test.lan',
'htaccess.RewriteBase' => '/',
'dbname' => 'nextcloud',
'dbhost' => '10.10.10.49',
'dbport' => '3306',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'nextcloud',
'dbpassword' => 'password',
'installed' => true,
// 'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\\OC\Memcache\\Memcached',
'memcached_servers' => array(
array('10.10.10.47', 11211),
),
'memcache.locking' => '\\OC\\Memcache\\Redis',
'filelocking.enabled' => 'true',
'redis' =>
array (
'host' => '10.10.10.46',
'port' =>6379,
'timeout' => 0.0,
),
);
Then i get this error in the nextcloud.log
\\OC\\Memcache\\Memcached not available for distributed cache","Code":0
I did set the bind address in the memcached.conf to 0.0.0.0 so it accepts all incoming connections and also added a rule to the firewall to allow incoming connections on port 11211.
I hope you guys cane give me some tipps.

ZfcUserDoctrineMongoODM Configuration examples

I am trying to configure ZendFramwork 2 to use MongoDB as the storage for user Authentication.
I already have installed what I believe are the correct modules and have a correctly installed instance of ZF2 running on Nginx. I also have an instance of Mongo running and I am already using this for another project. The modules declaration in application.config.php looks like this
'modules' => array(
'Application',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineMongoODM',
'DoctrineModule',
'DoctrineMongoODMModule'
)
Documentation is a bit thin on how to configure the system to get it working. Can anyone provide any code fragments around configuring the database settings to allow Mongo to run with ZfcUser, this is where I am at a loss now.
Any help, clues or cheat sheets would be greatly appreciated.
Darren Breeze
Have a look at Doctrine Mongo ODM module readme https://github.com/doctrine/DoctrineMongoODMModule :
copy
vendor/doctrine/doctrine-mongo-odm-module/config/module.doctrine-mongo-odm.local.php.dist
into your application's config/autoload directory, rename it to
module.doctrine-mongo-odm.local.php and make the appropriate changes.
With this config file you can configure your mongo connection, add
extra annotations to register, add subscribers to the event manager,
add filters to the filter collection, and drivers to the driver chain.
So you have something like this at your autoload config:
<?php
return array(
'doctrine' => array(
'connection' => array(
'odm_default' => array(
'server' => 'localhost',
'port' => '27017',
// 'connectionString' => null,
// 'user' => null,
// 'password' => null,
// 'dbname' => null,
// 'options' => array()
),
),
....
'configuration' => array(
'odm_default' => array(
... 'default_db' => 'myappdb',
)
)
So tune it and try to register at user/register. Collection name is user by default.

Zf2 + Doctrine 2 Authentication Adapter with Multiple or Alternate Columns

I am working on a site in which user can enter two email address(primary and secondary) along with password.
If user enters his primary email and password, he gets logged in successfully.
But, what I am trying to provide is if user enters his secondary email instead of primary, even then he gets logged in. And the problem I am getting is how to create an alternate Doctrine Auth Adapter or something like that.
this is what I have done in my module.config.php:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
),
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'User\Entity\LoginDetails',
'identity_property' => 'primary_email',
'credential_property' => 'password',
),
),
)
Is there any option to add an identity property which will be alternative ?
I am using Zend framework 2 and Doctrine 2
Is there any option to add an identity property which will be alternative ?
No, there is no such option built-in to DoctrineModule.
Consider extending DoctrineModule\Authentication\Adapter\ObjectRepository to override the authenticate() method.
Then, at minimum, you'll want to replace the default adapter with your new more different one. If you look at the various factories in DoctrineModule, you should be off to a good start.
Basically, one of your modules will want to override the doctrine.authenticationadapter.[orm|odm]_default configuration key in the ServiceManager. That will cause DoctrineModule to inject your extended ObjectRepository into the AuthenticationService in place of you the default one.

Zend_Cache Clean Method

I just tried to use Zend_Cache in my application, and it worked. The problem now is I am not sure where to put Zend_Cache clean() method in my code.
Here is my code:
// application/Bootstrap.php
protected function _initCache()
{
$dir = "./cache";
$frontendOptions = array(
'lifetime' => 10,
'content_type_memorization' => true,
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
),
'regexps' => array(
// cache the whole IndexController
'^/.*' => array('cache' => true),
'^/index/' => array('cache' => true),
// place more controller links here to cache them
)
);
$backendOptions = array(
'cache_dir' =>$dir
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
}
Where should I put the $cache->clean(/* something */);?
As you have configured our $frontend array to cache data for 10 seconds, so the data cached will automatically be remove after 10 second.
i would suggest that you can increase your time like
one hour : 3600 or 2 hours like 7200
However if later in your application you want to clean the entire cached data manually, simply write
$cache->clean();
This will clean the entire cached data. However if you want to remove specific data being cached, write
$cache->remove(‘mydata’);
for more use of cache see link
i am not associate with above link it is just for your knowledge
hope this will sure help you.

Zend_Cache_Frontend_Page does not recognize output without echo

I am trying to fiddle around with Zend_Cache, so I added following code to my action (will be moved to bootstrap later, I guess):
$frontendOptions = array(
'lifetime' => 7200,
'debug_header' => true, // für das Debuggen
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
'cache_with_post_variables' => true,
)
);
$backendOptions = array(
'cache_dir' => '/tmp/'
);
$cache = Zend_Cache::factory('Page', 'File',
$frontendOptions, $backendOptions
);
echo "hej";
var_dump($cache->start('someid'));
Zend generates a cache file containing hejbool(false) now, but apart from that it does not cache my page. According to a German book about zend framework, false is correct when there is no cache available. true is only returned when a cache was found.
When I debugged within Zend_Cache_Frontend_Page.php directly, it went down to the bottom of the start()-method, meaning that nothing went wrong (id given) and no cache was found, so one had to be generated. This was done (I can see it in /tmp/), but without the needed content.
So why does not not cache the output from Zend_View, but only direct output via echo?
I do not call any explicit function to render the view, but this did not seem necessary anymore (my views are always rendered automatically according to controller and action). I tried it for both a standard XHTML template (index.phtml) and an RSS template (index.rss.phtml).
Any ideas? Do you need any other code fragments?
When using the Zend_Cache_Frontend_Page you have to enable the disableOutputBuffering option. The reason is that Zend_Cache_Frontend_Page uses ob_start with a callback and it has to be the first call to ob_start otherwise it leads to that strange behaviour you've encountered.
To enable it you can either set it in your Bootstrap with
Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true);
or using the configuration file after your frontController-setup (here in the INI-style configuration):
resources.frontController.params.disableOutputBuffering = true