cleverage/cache-process-bundle
CleverAge/CacheProcessBundle integrates Symfony Cache with the CleverAge ProcessBundle, enabling caching within process workflows. Part of the CleverAge/ProcessBundle project, it supports Symfony stable and LTS releases for efficient process execution.
Cache Process Bundle wires cache reads and writes directly into your Symfony Workflow as tasks. Instead of hand-rolling cache logic inside each workflow step, you compose GetTask and SetTask into your places/transitions and let the bundle handle options, adapters, and miss behaviour.
composer require cleverage/cache-process-bundle
config/bundles.php (Symfony) and declare your cache adapters under cleverage_cache_process: in your bundle config. Adapters are collected by a compiler pass and keyed by code.# config/packages/workflow.yaml
framework:
workflows:
my_workflow:
places: [start, cached, done]
transitions:
fetch:
from: start
to: cached
metadata:
task: Cleverage\CacheProcessBundle\Task\GetTask
adapter: main
key: 'user_%userId%_profile'
store:
from: cached
to: done
metadata:
task: Cleverage\CacheProcessBundle\Task\SetTask
adapter: main
key: 'user_%userId%_profile'
expires_after: 3600
Options (adapter, key, value) do not have to be set at configuration level — they can be supplied entirely by the workflow input and are merged at runtime.GetTask reads key from the configured adapter. As of v2.2 you can control what happens on a miss with on_miss:
task: Cleverage\CacheProcessBundle\Task\GetTask
adapter: main
key: 'report_%reportId%'
on_miss: output_null # default: emits null to the main output
# on_miss: skip # sends the input to the error outputs
# on_miss: fail # fails the task
Choose skip when a missing cache should trigger a fallback branch, and fail when a missing cache is unexpected. output_null keeps the workflow's happy path flowing with a null value.
SetTask writes value to key on the configured adapter. Use the new expires_after option to set the per-item TTL:
task: Cleverage\CacheProcessBundle\Task\SetTask
adapter: main
key: 'report_%reportId%'
value: '@output.report'
expires_after: 86400 # store for one day
expires_after is optional — omit it to fall back to the adapter's default lifetime.
Options no longer need placeholders at configuration time. You can:
OptionsResolver, so invalid values surface as clear errors instead of silently flowing through (fixed in #23).Extend AbstractCacheTask to build your own caching tasks. Override getRequiredOptions() (new in v2.2) to declare which options must be present after merging:
use Cleverage\CacheProcessBundle\Task\AbstractCacheTask;
class PutTask extends AbstractCacheTask
{
protected function getRequiredOptions(): array
{
return [...parent::getRequiredOptions(), 'key'];
}
}
The bundle's tests cover custom tasks, options validation, context handling, null storage, and overwriting, so this extension point is well-exercised.
Register adapters via configuration (compiler pass picks them up) or programmatically with AdapterRegistry::addAdapter(). Since v2.2 the registry accepts an optional $serviceId argument, so duplicate code collisions report both service IDs in the exception — invaluable in large bundles.
composer.json:
"require": {
"php": "^8.2 || ^8.3 || ^8.4 || ^8.5",
"symfony/*": "^7.4 || ^8.0"
}
Invalid cache keys are only rejected by Symfony adapters when assert() is enabled (zend.assertions=1 in development). In production the same bad key may silently flow through. Don't rely on assertions for user-facing key validation.
Passing a scalar instead of an array to GetTask/SetTask used to trigger an opaque \TypeError from array_merge(). Since v2.2 it throws an explicit \UnexpectedValueException — catch or guard against this in custom workflow listeners.
Option values supplied by workflow input are now run through OptionsResolver. If you were relying on loose types (e.g. passing a string where an int TTL is expected) you may start seeing validation errors — cast early.
If two adapters are registered under the same code, the compiler pass throws. With v2.2 you get both service IDs in the message — keep that in mind when debugging DI extensions from third-party bundles.
on_miss semanticsoutput_null (default): main output receives null; workflow continues normally.skip: main output is bypassed and the input is forwarded to error outputs — your workflow must declare them.fail: throws. Use only when a miss genuinely indicates a broken pipeline.Mock GetTask/SetTask in isolation, or use Symfony's TaskTestCase if available in your workflow testing bundle. For unit tests around AbstractCacheTask subclasses, assert that getRequiredOptions() fails fast when a required option is missing.
AbstractCacheTask::getRequiredOptions() — define required options per task.AdapterRegistry::addAdapter() — add adapters programmatically with $serviceId for better diagnostics.code via configuration; extend it only if you need dynamic registration.How can I help you explore Laravel packages today?