Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check performance upgrade: remove dependency injection #125

Open
RoySegall opened this issue Jun 29, 2018 · 0 comments
Open

Check performance upgrade: remove dependency injection #125

RoySegall opened this issue Jun 29, 2018 · 0 comments

Comments

@RoySegall
Copy link
Owner

It seems that when using a depdancy injection the objection get's really really really big. This increase memory usage and maybe caching sizes. For now we have something like this:

class Memcache extends CacheBase implements HookContainerInterface {

  /**
   * @var NuntiusConfig
   */
  protected $config;

  /**
   * @var \Memcached
   */
  protected $memcached;

  /**
   * {@inheritdoc}
   */
  static function getContainer(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
    return new static($container->get('config'));
  }

  /**
   * Memcache constructor.
   *
   * @param NuntiusConfig $config
   */
  public function __construct(NuntiusConfig $config) {
    $this->config = $config;

    $connection = $config->getSetting('memcache');

    $this->memcached = new \Memcached();
    $this->memcached->addServer($connection['host'], $connection['port']);
  }
}

will be

class Memcache extends CacheBase implements HookContainerInterface {

  /**
   * @var NuntiusConfig
   */
  protected $config;

  /**
   * @var \Memcached
   */
  protected $memcached;

  /**
   * {@inheritdoc}
   */
  static function getContainer(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
    return new static($container->get('config'));
  }

  /**
   * Memcache constructor.
   *
   * @param NuntiusConfig $config
   */
  public function __construct(ContainerBuilder $container) {
    $this->container = $container;
  }

  protected function getMemcache() {
    return new Memcache();
  }

  protected function getConfig() {
    return $this->container->get('config');
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant