Skip to content

Commit e9f0361

Browse files
#35 Add demo.cache.set_get process using MemoryAdapter
1 parent 8729edb commit e9f0361

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
clever_age_process:
2+
configurations:
3+
demo.cache.set_get:
4+
description: >
5+
A simple process which set and get cached values
6+
help: >
7+
Ex: bin/console cleverage:process:execute demo.cache.set_get
8+
options:
9+
ui:
10+
source: Bar
11+
target: Foo
12+
tasks:
13+
start:
14+
service: '@CleverAge\ProcessBundle\Task\DummyTask'
15+
outputs: [ data, get, get_missing ]
16+
17+
data:
18+
service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
19+
outputs: [ format ]
20+
options:
21+
output:
22+
- key: 'key1'
23+
column1: value1-1
24+
column2: value2-1
25+
column3: value3-1
26+
- key: 'key2'
27+
column1: value1-2
28+
column2: value2-2
29+
column3: value3-2
30+
- key: 'key3'
31+
column1: ''
32+
column2: null
33+
column3: value3-3
34+
format:
35+
service: '@CleverAge\ProcessBundle\Task\TransformerTask'
36+
options:
37+
transformers:
38+
mapping:
39+
mapping:
40+
key:
41+
code: '[key]'
42+
value:
43+
code: '.'
44+
outputs: [ set ]
45+
46+
set:
47+
service: '@CleverAge\CacheProcessBundle\Task\SetTask'
48+
options:
49+
adapter: 'memory'
50+
key: '' # overrided by input'
51+
value: '' # overrided by input
52+
53+
get:
54+
service: '@CleverAge\CacheProcessBundle\Task\GetTask'
55+
options:
56+
adapter: 'memory'
57+
key: 'key2'
58+
outputs: [ debug ]
59+
60+
get_missing:
61+
service: '@CleverAge\CacheProcessBundle\Task\GetTask'
62+
options:
63+
adapter: 'memory'
64+
key: 'missing'
65+
outputs: [ debug ]
66+
67+
debug:
68+
service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'

config/services.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ services:
5656
$uri: 'https://apicarto.ign.fr/api'
5757
tags:
5858
- { name: cleverage.rest.client }
59+
60+
# For cleverage/cache-process-bundle
61+
app.cleverage_cache_process.adapter.memory:
62+
class: App\Adapter\MemoryAdapter
63+
tags:
64+
- { name: cleverage.cache.adapter }

src/Adapter/MemoryAdapter.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the CleverAge/ProcessBundleDemo package.
7+
*
8+
* Copyright (c) Clever-Age
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace App\Adapter;
15+
16+
use CleverAge\CacheProcessBundle\Adapter\Adapter;
17+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
18+
19+
class MemoryAdapter extends Adapter
20+
{
21+
public function __construct()
22+
{
23+
$cache = new ArrayAdapter(
24+
// the default lifetime (in seconds) for cache items that do not define their
25+
// own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
26+
// until the current PHP process finishes)
27+
$defaultLifetime = 0,
28+
29+
// if true, the values saved in the cache are serialized before storing them
30+
$storeSerialized = true,
31+
32+
// the maximum lifetime (in seconds) of the entire cache (after this time, the
33+
// entire cache is deleted to avoid stale data from consuming memory)
34+
$maxLifetime = 0,
35+
36+
// the maximum number of items that can be stored in the cache. When the limit
37+
// is reached, cache follows the LRU model (least recently used items are deleted)
38+
$maxItems = 0
39+
);
40+
parent::__construct($cache, 'memory');
41+
}
42+
}

0 commit comments

Comments
 (0)