-
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.
Merge pull request #10 from Traackr/CAMP-881-redis-sets
CAMP-881: Add CacheEnginesHelper::writeWithParent.
- Loading branch information
Showing
14 changed files
with
585 additions
and
43 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
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,12 @@ | ||
FROM php:7.1-fpm-alpine | ||
RUN apk update && apk add build-base | ||
RUN apk add zlib-dev git zip libmcrypt-dev \ | ||
&& docker-php-ext-install zip \ | ||
&& docker-php-ext-install mcrypt \ | ||
&& docker-php-ext-enable mcrypt | ||
RUN curl -sS https://getcomposer.org/installer | php \ | ||
&& mv composer.phar /usr/local/bin/ \ | ||
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer | ||
COPY . /app | ||
WORKDIR /app | ||
ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" |
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,19 @@ | ||
help: ## This command | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
build: ## Builds the image using docker-compose | ||
docker-compose build --no-cache cakephp-cache-engines | ||
start: ## Run the application in the background | ||
docker-compose up -d | ||
start-build: ## Build the application and run application | ||
docker-compose up -d --force-recreate --remove-orphans | ||
stop: ## Stop application | ||
@docker-compose stop | ||
run-composer-install: ## Run composer install | ||
docker-compose exec -T cakephp-cache-engines \ | ||
composer install | ||
run-unit-tests: ## Run unit tests | ||
docker-compose exec -T cakephp-cache-engines \ | ||
/app/bin/phpunit test |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "3.7" | ||
services: | ||
cakephp-cache-engines: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
network: host | ||
container_name: cakephp-cache-engines | ||
restart: always | ||
volumes: | ||
- ./:/app:rw |
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,121 @@ | ||
<?php | ||
|
||
/** | ||
* Helper utility methods for the advanced features offered by | ||
* some Cache Engines, such as the RedisTreeEngine. | ||
*/ | ||
class CacheEnginesHelper | ||
{ | ||
/** | ||
* Write data for key into a cache engine with one or more 'parent'. | ||
* | ||
* The following is a modified version of: | ||
* https://github.com/cakephp/cakephp/blob/2.10.22/lib/Cake/Cache/Cache.php | ||
* The modifications are limited to the addition of | ||
* the `$parentKey` parameter. | ||
* | ||
* ### Usage: | ||
* | ||
* Write the value for a single key with a single parent: | ||
* | ||
* `Cache::write('cache_key', $data, $config, 'parent_cache_key');` | ||
* | ||
* Write the value for a single key with multiple parents: | ||
* | ||
* `Cache::write('cache_key', $data, $config, [ | ||
* 'parent_cache_key_1', | ||
* 'parent_cache_key_2', | ||
* ]);` | ||
* | ||
* Write the values for multiple keys with the same parent: | ||
* | ||
* `Cache::write( | ||
* '[cache_key_1,cache_key_2]', | ||
* $data, | ||
* $config, | ||
* 'parent_cache_key_1' | ||
* );` | ||
* | ||
* Write the values for multiple keys with the same parents: | ||
* | ||
* `Cache::write( | ||
* '[cache_key_1,cache_key_2]', | ||
* $data, | ||
* $config, | ||
* [ | ||
* 'parent_cache_key_1', | ||
* 'parent_cache_key_2', | ||
* ] | ||
* );` | ||
* Write the values for multiple keys with different parents: | ||
* | ||
* `Cache::write( | ||
* '[cache_key_1,cache_key_2]', | ||
* $data, | ||
* $config, | ||
* [ | ||
* 'cache_key_1' => [ | ||
* 'parent_cache_key_1' | ||
* ], | ||
* 'cache_key_2' => [ | ||
* 'parent_cache_key_2' | ||
* ] | ||
* ] | ||
* );` | ||
* | ||
* Writing to a specific cache config: | ||
* | ||
* `Cache::write('cached_data', $data, 'long_term');` | ||
* | ||
* @param string $key Identifier for the data | ||
* @param mixed $value Data to be cached - anything except a resource | ||
* @param string $config Optional string configuration name to write to | ||
* Defaults to 'default' | ||
* @param string|array $parentKey Parent key that data is a dependent child of | ||
* @return bool True if the data was successfully cached, false on failure | ||
*/ | ||
public static function writeWithParent( | ||
$key, | ||
$value, | ||
$config = 'default', | ||
$parentKey = '' | ||
) { | ||
$settings = Cache::settings($config); | ||
|
||
if (empty($settings)) { | ||
return false; | ||
} | ||
if (!Cache::isInitialized($config)) { | ||
return false; | ||
} | ||
$key = Cache::engine($config)->key($key); | ||
|
||
if (!$key || is_resource($value)) { | ||
return false; | ||
} | ||
|
||
$success = false; | ||
if (method_exists(Cache::engine($config), 'writeWithParent')) { | ||
$success = Cache::engine($config)->writeWithParent( | ||
$settings['prefix'] . $key, | ||
$value, | ||
$settings['duration'], | ||
$parentKey | ||
); | ||
} | ||
Cache::set(null, $config); | ||
if ($success === false && $value !== '') { | ||
trigger_error( | ||
__d( | ||
'cake_dev', | ||
"%s cache was unable to write '%s' to %s cache", | ||
$config, | ||
$key, | ||
Cache::$_engines[$config]->settings['engine'] | ||
), | ||
E_USER_WARNING | ||
); | ||
} | ||
return $success; | ||
} | ||
} |
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
Oops, something went wrong.