-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a55f678
commit 5a839f4
Showing
9 changed files
with
231 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ on: | |
env: | ||
SIMPLETEST_DB: "mysql://drupal:[email protected]:3306/drupal" | ||
SIMPLETEST_BASE_URL: "http://127.0.0.1:8080" | ||
MODULE_FOLDER: "drupal-cache" | ||
MODULE_REPO: "momentohq/drupal-cache" | ||
DRUPAL_MODULE_NAME: "momento_cache" | ||
DRUPAL_CORE_VERSION: 9.4.x | ||
|
@@ -60,7 +61,7 @@ jobs: | |
# modules/contrib/$DRUPAL_MODULE_NAME or modules/custom/$DRUPAL_MODULE_NAME. | ||
- name: Set module folder | ||
run: | | ||
echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/$DRUPAL_MODULE_NAME" \ | ||
echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/$MODULE_FOLDER" \ | ||
>> $GITHUB_ENV | ||
# Clone Drupal core into $DRUPAL_ROOT folder. | ||
|
@@ -113,13 +114,14 @@ jobs: | |
php -d sendmail_path=$(which true); vendor/bin/drush --yes -v \ | ||
site-install minimal --db-url="$SIMPLETEST_DB" | ||
vendor/bin/drush pm-list --type=module | ||
vendor/bin/drush en $DRUPAL_MODULE_NAME -y | ||
# vendor/bin/drush en $DRUPAL_MODULE_NAME -y | ||
# find /home/runner/drupal/modules | ||
- name: Run PHPCS | ||
working-directory: ${{ env.DRUPAL_ROOT }} | ||
run: | | ||
vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal \ | ||
--extensions=php,module,inc,install,test,info | ||
# vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal \ | ||
# --extensions=php,module,inc,install,test,info | ||
- name: Start Drush webserver and chromedriver | ||
working-directory: ${{ env.DRUPAL_ROOT }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
services: | ||
momento_cache.factory: | ||
class: Drupal\momento_cache\Client\MomentoClientFactory | ||
cache.backend.momento_cache: | ||
class: Drupal\momento_cache\MomentoCacheBackendFactory | ||
arguments: [] | ||
cache_tags.invalidator.checksum: | ||
class: Drupal\momento_cache\MomentoTimestampInvalidator | ||
arguments: ['@cache.backend.momento_cache'] | ||
tags: | ||
- { name: cache_tags_invalidator } | ||
arguments: ['@momento_cache.factory', '@cache_tags.invalidator.checksum'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Drupal\momento_cache\Client; | ||
|
||
use Drupal\Core\DependencyInjection\ContainerNotInitializedException; | ||
use Drupal\Core\Site\Settings; | ||
use Drupal\Core\Logger\LoggerChannelTrait; | ||
use Momento\Auth\StringMomentoTokenProvider; | ||
use Momento\Cache\CacheClient; | ||
use Momento\Config\Configurations\Laptop; | ||
|
||
class MomentoClientFactory { | ||
|
||
use LoggerChannelTrait; | ||
|
||
private $authProvider; | ||
private $cachePrefix; | ||
private $client; | ||
private $containerCacheCreated = false; | ||
|
||
public function __construct() { | ||
$settings = Settings::get('momento_cache', []); | ||
$authToken = array_key_exists('api_token', $settings) ? | ||
$settings['api_token'] : getenv("MOMENTO_API_TOKEN"); | ||
$this->cachePrefix = array_key_exists('cache_name_prefix', $settings) ? | ||
$settings['cache_name_prefix'] : 'drupal-'; | ||
$this->authProvider = new StringMomentoTokenProvider($authToken); | ||
} | ||
|
||
public function get() { | ||
if (!$this->client) { | ||
$this->client = new CacheClient(Laptop::latest(), $this->authProvider, 30); | ||
// Ensure "container" cache exists | ||
// TODO: add logging | ||
if (!$this->containerCacheCreated) { | ||
$createResponse = $this->client->createCache($this->cachePrefix . 'container'); | ||
if ($createResponse->asSuccess()) { | ||
$this->containerCacheCreated = true; | ||
} elseif ($createResponse->asError()) { | ||
try { | ||
$this->getLogger('momento_cache')->error( | ||
"Error getting Momento client: " . $createResponse->asError()->message() | ||
); | ||
} catch(ContainerNotInitializedException $e) { | ||
// we don't have access to getLogger() until the container is initialized | ||
} | ||
} | ||
} | ||
} | ||
return $this->client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
// TODO: this class is not used anywhere, but it is referenced in the bootstrap_container_definition | ||
// in settings.php. It's not hurting anything, but needs to be removed. | ||
|
||
namespace Drupal\momento_cache\Invalidator; | ||
|
||
use Drupal\Core\Cache\CacheTagsInvalidatorInterface; | ||
use Drupal\momento_cache\Client\MomentoClientFactory; | ||
|
||
class MomentoTimestampInvalidator { | ||
|
||
private $bin = '_momentoTags'; | ||
|
||
public function __construct(MomentoClientFactory $factory) { | ||
$this->client = $factory->get(); | ||
print("\n\n\nTIMESTAMP INVALIDATOR CLIENT IS ALIVE"); | ||
} | ||
|
||
public function invalidateTags(array $tags) { | ||
return; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.