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

Drupal only changes #4

Merged
merged 4 commits into from Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"lcache/lcache": "v0.2.*"
"lcache/lcache": "v0.3.*"
},
"require-dev": {
"phpunit/phpunit": "4.*",
Expand Down
4 changes: 2 additions & 2 deletions lcache.install
Expand Up @@ -30,7 +30,7 @@ function lcache_schema() {
'address' => array(
'description' => 'Cache entry address (bin and key).',
'type' => 'varchar_ascii',
'length' => 255,
'length' => 512,
'not null' => FALSE,
'default' => NULL,
),
Expand Down Expand Up @@ -99,6 +99,7 @@ function lcache_install() {
ALTER TABLE {lcache_tags}
ADD CONSTRAINT {lcache_tags_event_id}
FOREIGN KEY (event_id) REFERENCES {lcache_events} (event_id)
ON DELETE CASCADE
');
}

Expand All @@ -111,4 +112,3 @@ function lcache_uninstall() {
DROP FOREIGN KEY IF EXISTS {lcache_tags_event_id}
');
}

10 changes: 9 additions & 1 deletion lcache.services.yml
@@ -1,4 +1,12 @@
services:
cache.backend.lcache:
class: Drupal\lcache\BackendFactory
arguments: []
arguments: ['@database']
lcache.integrated:
class: LCache\Integrated
factory: cache.backend.lcache:getIntegratedLCache
cache_tags.invalidator.lcache:
class: Drupal\lcache\BackendInvalidator
arguments: ['@lcache.integrated']
tags:
- { name: cache_tags_invalidator}
1 change: 0 additions & 1 deletion src/Backend.php
Expand Up @@ -7,7 +7,6 @@

namespace Drupal\lcache;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;

/**
Expand Down
26 changes: 21 additions & 5 deletions src/BackendFactory.php
Expand Up @@ -7,23 +7,28 @@

namespace Drupal\lcache;

use Drupal\Core\Database\Connection;

class BackendFactory {

protected $integrated;

protected function get_pdo_handle() {
// @TODO: Use Drupal's connection arguments or actually pull Drupal's PDO handle.
$dsn = 'mysql:host='. $_ENV['DB_HOST']. ';port='. $_ENV['DB_PORT'] .';dbname='. $_ENV['DB_NAME'];
$options = array(\PDO::ATTR_TIMEOUT => 2, \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="ANSI_QUOTES"');
$dbh = new \PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $options);
$db_info = $this->connection->getConnectionOptions();
$dsn = 'mysql:host='. $db_info['host']. ';port='. $db_info['port'] .';dbname='. $db_info['database'];
$options = array(\PDO::ATTR_TIMEOUT => 2, \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="ANSI_QUOTES,STRICT_ALL_TABLES"');
$dbh = new \PDO($dsn, $db_info['username'], $db_info['password'], $options);
$dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $dbh;
}

/**
* Constructs the BackendFactory object.
*/
public function __construct() {
public function __construct(Connection $connection) {

$this->connection = $connection;

// Use the Null L1 cache for the CLI.
$l1 = new \LCache\NullL1();
if (php_sapi_name() !== 'cli') {
Expand All @@ -46,4 +51,15 @@ public function __construct() {
public function get($bin) {
return new Backend($bin, $this->integrated);
}

/**
* Gets an LCache Backend for the specified cache bin.
*
* @return \LCache\Integrated
* The integrated cache backend.
*/
public function getIntegratedLCache() {
return $this->integrated;
}

}
29 changes: 29 additions & 0 deletions src/BackendInvalidator.php
@@ -0,0 +1,29 @@
<?php

/**
* @file
* Contains \Drupal\lcache\BackendInvalidator.
*/

namespace Drupal\lcache;

use Drupal\Core\Cache\CacheTagsInvalidatorInterface;

class BackendInvalidator implements CacheTagsInvalidatorInterface {

protected $integrated;

public function __construct(\LCache\Integrated $integrated) {
$this->integrated = $integrated;
}

/**
* {@inheritdoc}
*/
public function invalidateTags(array $tags) {
foreach ($tags as $tag) {
$this->integrated->deleteTag($tag);
}
}

}