Nettrine/Cache + Memcached + Docker

xhtmlkoder
Člen | 15
+
0
-

Ahoj, prosim pritomne o pomoc. Bud neco prehlizim, nebo uz fakt nevim. Snazim se o implementaci Nettrine/Cache pomoci driveru Memcached. PHP i server by mel byt v poradku nastaveny. Kdyz jsem zkousel manualni implementaci pomoci Nette/cache, tak to fungovalo. Ale pro Nettrine/Cache to ne a ne rozchodit.

V momente, kdy nastavim Memcached driver, dostanu zpet „Call to a member function get() on null“ z „File: …/Doctrine/Common/Cache/MemcachedCache.php:49“
Jeste nutno dodat, ze jedu na Docker kontejnerech s Nginx-proxy + Apache + PHP-fpm 7.4 + Memcached 1.6 + Postgresql 12 (zaklad systemu na centos 8). Teoreticky me napada, ze se snazi Nettrine pripojit na 127.0.0.1:11211. Coz uz dockeru nejde a musi se pripojit na nazevKontejneru:11211 . Ale ani za boha nemohu najit, jak u Memcached tohle v Nettrine zmenit.

# Extension > Nettrine
#
extensions:

	# Dbal
	nettrine.dbal: Nettrine\DBAL\DI\DbalExtension
	nettrine.dbal.console: Nettrine\DBAL\DI\DbalConsoleExtension

	# Orm
	nettrine.orm: Nettrine\ORM\DI\OrmExtension
	nettrine.orm.cache: Nettrine\ORM\DI\OrmCacheExtension
	nettrine.orm.console: Nettrine\ORM\DI\OrmConsoleExtension
	nettrine.orm.annotations: Nettrine\ORM\DI\OrmAnnotationsExtension

	nettrine.annotations: Nettrine\Annotations\DI\AnnotationsExtension
	nettrine.cache: Nettrine\Cache\DI\CacheExtension
	nettrine.migrations: Nettrine\Migrations\DI\MigrationsExtension
	nettrine.fixtures: Nettrine\Fixtures\DI\FixturesExtension

	nettrine.extensions.atlantic18: Nettrine\Extensions\Atlantic18\DI\Atlantic18BehaviorExtension

nettrine.dbal:
	debug:
		panel: %debugMode%
	configuration:
#		sqlLogger: Nettrine\DBAL\Logger\PsrLogger(@Monolog\Logger)
#		resultCache: Nette\Caching\Cache
	connection:
		driver: %database.driver%
		host: %database.host%
		user: %database.user%
		password: %database.password%
		dbname: %database.dbname%
		types:
			geography:
				class: Jsor\Doctrine\PostGIS\Types\GeographyType
				commented: false

nettrine.orm:
	entityManagerDecoratorClass: App\Model\Database\EntityManager
	configuration:
		autoGenerateProxyClasses: %debugMode%

nettrine.orm.annotations:
	paths:
		- %appDir%/model/Database/Entity
		- %appDir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity
		- %appDir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity

#nettrine.orm.cache:
#	defaultDriver: Doctrine\Common\Cache\MemcacheCache

nettrine.cache:
	driver: Doctrine\Common\Cache\MemcachedCache
#	driver: Doctrine\Common\Cache\ArrayCache()
#	driver: Doctrine\Common\Cache\VoidCache

nettrine.migrations:
	table: doctrine_migrations
	column: version
	directory: %rootDir%/db/Migrations
	namespace: Database\Migrations
	versionsOrganization: null

nettrine.fixtures:
	paths:
		- %rootDir%/db/Fixtures

decorator:
	Doctrine\Common\EventSubscriber:
		tags: [nettrine.subscriber]

nettrine.extensions.atlantic18:
	loggable: true
	sluggable: true
	softDeleteable: true
	treeable: true
	blameable: true
	timestampable: true
	translatable:
		translatable: en
		default: en
		translationFallback: false
		persistDefaultTranslation: true
		skipOnLoad: false
	uploadable: false
	sortable: true
	ipTraceable:
		ipValue: @Nette\Http\IRequest::getRemoteAddress()

services:
	- Nettrine\Migrations\Events\FixPostgreSQLDefaultSchemaSubscriber

EntityManager (Zde si nacitam Memcached pro Nette/cache)

<?php declare(strict_types = 1);

namespace App\Model\Database;

use App\Model\Database\Repository\AbstractRepository;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Nette\Caching\Cache;
use Nette\Caching\IStorage;
use Nettrine\ORM\EntityManagerDecorator;

class EntityManager extends EntityManagerDecorator
{
	/** @var IStorage */
	protected $storage;

	/** @var Cache */
	public $cache;

	public function __construct(EntityManagerInterface $wrapped, IStorage $storage)
	{
		parent::__construct($wrapped);

		$this->storage = $storage;
		$this->cache = new Cache($storage, 'memcache');
	}

	use TRepositories;

	/**
	 * @param string $entityName
	 * @return AbstractRepository<T>|ObjectRepository<T>
	 * @internal
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
	 * @phpstan-template T
	 * @phpstan-param class-string<T> $entityName
	 */
	public function getRepository($entityName): ObjectRepository
	{
		return parent::getRepository($entityName);
	}

}
{
	"name": "planette/nutella-project",
	"license": "MIT",
	"type": "project",
	"require": {
		"php": "^7.4",

		"contributte/bootstrap": "^0.4.0",
		"contributte/application": "^0.4.0",
		"contributte/di": "^0.4.1",
		"contributte/cache": "^0.5.0",
		"contributte/http": "^0.3.0",
		"contributte/forms": "^0.4.0",
		"contributte/mail": "^0.5.0",
		"contributte/security": "^0.3.0",
		"contributte/utils": "^0.4.1",
		"contributte/latte": "^0.4.0",
		"contributte/tracy": "^0.4.1",

		"contributte/console": "^0.8.0",
		"contributte/console-extra": "^0.5.1",
		"contributte/event-dispatcher": "^0.7.0",
		"contributte/event-dispatcher-extra": "^0.7.1",
		"contributte/monolog": "^0.5.0",
		"contributte/neonizer": "^0.4.0",
		"contributte/mailing": "^0.3.1",

		"nettrine/annotations": "^0.6.0",
		"nettrine/orm": "^0.5.0",
		"nettrine/dbal": "^0.6.0",
		"nettrine/cache": "^0.1.0",
		"nettrine/migrations": "^0.7.0",
		"nettrine/fixtures": "^0.5.0",
		"jsor/doctrine-postgis": "^1.7",
		"bicisteadm/webloader-reload": "^3.0",
		"joseki/webloader-filters": "^1.1",
		"contributte/translation": "^0.6.0",
		"nettrine/extensions-atlantic18": "^0.5.0",
		"contributte/guzzlette": "^3.0",
		"google/apiclient": "^2.4",
		"sentry/sdk": "2.1.0",
		"contributte/recaptcha": "^3.3"
	},
	"require-dev": {
		"ninjify/qa": "^0.10.0",
		"ninjify/nunjuck": "^0.3.0",
		"contributte/dev": "^0.2.0",
		"mockery/mockery": "^1.3.0",
		"nelmio/alice": "^3.5.8",
		"phpunit/phpunit": "^8.5.0",
		"phpstan/phpstan": "^0.12.0",
		"phpstan/phpstan-doctrine": "^0.12.0",
		"phpstan/phpstan-deprecation-rules": "^0.12.0",
		"phpstan/phpstan-nette": "^0.12.0",
		"phpstan/phpstan-phpunit": "^0.12.0",
		"phpstan/phpstan-strict-rules": "^0.12.0"
	},
	"autoload": {
		"psr-4": {
			"App\\Model\\": "app/model",
			"App\\Domain\\": "app/domain",
			"App\\UI\\": "app/ui",
			"Database\\": "db",
			"App\\Modules\\": "app/modules"
		}
	},
	"autoload-dev": {
		"psr-4": {
			"Tests\\Toolkit\\": "tests/toolkit",
			"Tests\\Cases\\": "tests/cases"
		}
	},
	"prefer-stable": true,
	"minimum-stability": "dev",
	"scripts": {
		"post-install-cmd": [
			"Contributte\\Neonizer\\NeonizerExtension::process"
		],
		"post-update-cmd": [
			"Contributte\\Neonizer\\NeonizerExtension::process"
		]
	},
	"extra": {
		"neonizer": {
			"files": [
				{
					"dist-file": "app/config/config.local.neon.dist"
				}
			]
		}
	},
	"config": {
		"platform": {
			"php": "7.4"
		}
	}
}

Editoval xhtmlkoder (3. 6. 2020 14:44)

Felix
Nette Core | 1245
+
0
-

Ahoj,

  1. Diky za pouzivas contributte/webapp-skeleton.
  2. Podle dokumentace budes muset jeste doplnit nastaveni pro Memcache(d). Viz https://www.doctrine-project.org/…0/index.html#….
xhtmlkoder
Člen | 15
+
0
-

Sice je to pro me trochu vyssi divci, ale nutela me zaujala. O napojeni jak jsi posilal jsem se pokousel. Ale i tak jsem vzdy v ENtity manageru dostal v getCache() sice memcached driver, ale bez spojeni. Mohl by jsi byt prosim trochu konkretnejsi, jestli ti to cas a sily umozni? Dekuji. Kdyz jsem se to pokousel napojit pres servisu, tak byl zase problem v nettrine.dbal.cache a pote v nettrine.orm.cache. Ze neznaly cache servisu..

Marek Bartoš
Nette Blogger | 1274
+
0
-

Kupříkladu takto

nettrine.cache:
	driver:
		create: Doctrine\Common\Cache\MemcachedCache
		setup:
			- setMemcached(@\Memcached)

MemcachedCache nepřijímá spojení v constructoru, ale v setteru, takže ti nezafungoval autowiring a metoda se namísto na Memcached volala na null, jak stálo v chybě

Editoval Mabar (3. 6. 2020 18:12)

xhtmlkoder
Člen | 15
+
0
-

Panove diky za posunuti. A jak ted toho workera dostanu do EntityManager? Protoze nyni kdyz si zavolam v EM ->getCache(), tak dostanu:

Doctrine\ORM\Cache\DefaultCache
em private => Doctrine\ORM\EntityManager
uow private => Doctrine\ORM\UnitOfWork
cacheFactory private => Doctrine\ORM\Cache\DefaultCacheFactory
cache private => Doctrine\Common\Cache\MemcachedCache
memcached private => null
namespace private => ""
namespaceVersion private => null
regionsConfig private => Doctrine\ORM\Cache\RegionsConfiguration
lifetimes private => array ()
lockLifetimes private => array ()
defaultLifetime private => 3600
defaultLockLifetime private => 60
timestampRegion private => null
regions private => array ()
fileLockRegionDirectory private => null
queryCaches private => array ()
defaultQueryCache private => null

tedy memcached private ⇒ null

class MemcachedWorker extends \Memcached
{
	/** @var Cache */
	private $cache;

	public function __construct()
	{
		parent::__construct();

		$memcached = new \Memcached();
		$memcached->addServer('memcached', 11211);

		$cache = new MemcachedCache();
		$cache->setMemcached($memcached);

		$this->cache = $cache;
	}

}
class EntityManager extends EntityManagerDecorator
{

	/** @var \Memcached */
	private $cache;

	public function __construct(EntityManagerInterface $wrapped, \Memcached $cache)
	{
		parent::__construct($wrapped, $cache);

		$this->cache = $cache;

		dump($this->getCache());
		dump($cache); die();
	}
xhtmlkoder
Člen | 15
+
0
-

ja su vulk. jsem si to prepisoval v configu nettrine. Nicmene ted mam v memcached workera a ne memcached:

Doctrine\ORM\Cache\DefaultCache
em private => Doctrine\ORM\EntityManager
uow private => Doctrine\ORM\UnitOfWork
cacheFactory private => Doctrine\ORM\Cache\DefaultCacheFactory
cache private => Doctrine\Common\Cache\MemcachedCache
memcached private => App\Model\Utils\MemcachedWorker #706a { ... }
namespace private => ""
namespaceVersion private => null
regionsConfig private => Doctrine\ORM\Cache\RegionsConfiguration
lifetimes private => array ()
lockLifetimes private => array ()
defaultLifetime private => 3600
defaultLockLifetime private => 60
timestampRegion private => null
regions private => array ()
fileLockRegionDirectory private => null
queryCaches private => array ()
defaultQueryCache private => null