Skip to content

Commit

Permalink
Merge pull request #161 from City-of-Helsinki/UHF-9978
Browse files Browse the repository at this point in the history
UHF-9978:  Interface for CacheTagInvalidator service
  • Loading branch information
tuutti authored Apr 17, 2024
2 parents 127d597 + a775005 commit ccf66eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions helfi_api_base.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ services:
- '@datetime.time'
- '@helfi_api_base.pubsub_settings'

Drupal\helfi_api_base\Cache\CacheTagInvalidatorInterface: '@helfi_api_base.cache_tag_invalidator'
Drupal\helfi_api_base\Cache\CacheTagInvalidator: '@helfi_api_base.cache_tag_invalidator'
helfi_api_base.cache_tag_invalidator:
class: Drupal\helfi_api_base\Cache\CacheTagInvalidator
Expand Down
15 changes: 3 additions & 12 deletions src/Cache/CacheTagInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* A service to invalidate cache tags on all instances.
*/
final class CacheTagInvalidator {
final class CacheTagInvalidator implements CacheTagInvalidatorInterface {

/**
* Constructs a new instance.
Expand All @@ -24,17 +24,9 @@ public function __construct(
}

/**
* Invalidates given cache tags.
*
* @param array $tags
* An array of cache tags.
* @param array $instances
* The instances to flush caches from.
*
* @return $this
* The self.
* {@inheritdoc}
*/
public function invalidateTags(array $tags, array $instances = []) : self {
public function invalidateTags(array $tags, array $instances = []) : void {
try {
$this->pubSubManager->sendMessage([
'tags' => $tags,
Expand All @@ -43,7 +35,6 @@ public function invalidateTags(array $tags, array $instances = []) : self {
}
catch (ConnectionException) {
}
return $this;
}

}
25 changes: 25 additions & 0 deletions src/Cache/CacheTagInvalidatorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_api_base\Cache;

/**
* A service to invalidate cache tags on all instances.
*/
interface CacheTagInvalidatorInterface {

/**
* Invalidates given cache tags.
*
* @param array $tags
* An array of cache tags.
* @param array $instances
* The instances to flush caches from.
*/
public function invalidateTags(
array $tags,
array $instances = []
): void;

}

0 comments on commit ccf66eb

Please sign in to comment.