Skip to content

Commit dec98c0

Browse files
Merge branch 'release-2025-winter' of github.com:ProcessMaker/processmaker into epic/FOUR-20308
2 parents 294eba2 + 528c067 commit dec98c0

File tree

250 files changed

+16302
-4596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+16302
-4596
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ OPEN_AI_SECRET="sk-O2D..."
4747
AI_MICROSERVICE_HOST="http://localhost:8010"
4848
PROCESS_REQUEST_ERRORS_RATE_LIMIT=1
4949
PROCESS_REQUEST_ERRORS_RATE_LIMIT_DURATION=86400
50+
CUSTOM_EXECUTORS=false
51+
CACHE_SETTING_DRIVER=cache_settings
52+
CACHE_SETTING_PREFIX=settings

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log
1919
/public/img
2020
/public/fonts
2121
/public/mix-manifest.json
22+
/public/stats.json
2223
tests/js/coverage
2324
tests/coverage-report
2425
tests/coverage-report/*
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace ProcessMaker\Cache;
4+
5+
use Illuminate\Cache\CacheManager;
6+
use ProcessMaker\Cache\Monitoring\CacheMetricsDecorator;
7+
use ProcessMaker\Cache\Monitoring\CacheMetricsInterface;
8+
use ProcessMaker\Cache\Monitoring\PrometheusMetricsManager;
9+
10+
abstract class AbstractCacheFactory implements CacheFactoryInterface
11+
{
12+
protected static ?CacheInterface $testInstance = null;
13+
14+
/**
15+
* Set a test instance for the factory
16+
*
17+
* @param CacheInterface|null $instance
18+
*/
19+
public static function setTestInstance(?CacheInterface $instance): void
20+
{
21+
static::$testInstance = $instance;
22+
}
23+
24+
/**
25+
* Create a new cache instance with metrics monitoring
26+
*
27+
* @param CacheManager $cacheManager
28+
* @param CacheMetricsInterface $metrics
29+
* @return CacheInterface
30+
*/
31+
public static function create(CacheManager $cacheManager, CacheMetricsInterface $metrics): CacheInterface
32+
{
33+
if (static::$testInstance !== null) {
34+
return static::$testInstance;
35+
}
36+
37+
// Create base cache instance
38+
$cache = static::createInstance($cacheManager);
39+
40+
// Wrap with metrics decorator
41+
return new CacheMetricsDecorator($cache, $metrics);
42+
}
43+
44+
/**
45+
* Get the current cache instance
46+
*
47+
* @return CacheInterface
48+
*/
49+
protected static function getInstance(): CacheInterface
50+
{
51+
return static::create(app('cache'), app()->make(PrometheusMetricsManager::class));
52+
}
53+
54+
/**
55+
* Create the specific cache instance
56+
*
57+
* @param CacheManager $cacheManager
58+
* @return CacheInterface
59+
*/
60+
abstract protected static function createInstance(CacheManager $cacheManager): CacheInterface;
61+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace ProcessMaker\Cache;
4+
5+
use Illuminate\Cache\CacheManager;
6+
use ProcessMaker\Cache\Monitoring\CacheMetricsInterface;
7+
8+
interface CacheFactoryInterface
9+
{
10+
/**
11+
* Create a new cache instance with metrics monitoring
12+
*
13+
* @param CacheManager $cacheManager
14+
* @param CacheMetricsInterface $metrics
15+
* @return CacheInterface
16+
*/
17+
public static function create(CacheManager $cacheManager, CacheMetricsInterface $metrics): CacheInterface;
18+
}

ProcessMaker/Cache/CacheInterface.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace ProcessMaker\Cache;
4+
5+
interface CacheInterface
6+
{
7+
/**
8+
* Fetches a value from the cache.
9+
*
10+
* @param string $key The unique key of this item in the cache.
11+
* @param mixed $default Default value to return if the key does not exist.
12+
*
13+
* @return mixed The value of the item from the cache, or $default in case of cache miss.
14+
*/
15+
public function get(string $key, mixed $default = null): mixed;
16+
17+
/**
18+
* Fetches a value from the cache, or stores the value from the callback if the key exists.
19+
*
20+
* @param string $key The unique key of this item in the cache.
21+
* @param callable $callback The callback that will return the value to store in the cache.
22+
*
23+
* @return mixed The value of the item from the cache, or $default in case of cache miss.
24+
*
25+
* @throws \InvalidArgumentException
26+
*/
27+
public function getOrCache(string $key, callable $callback): mixed;
28+
29+
/**
30+
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
31+
*
32+
* @param string $key The key of the item to store.
33+
* @param mixed $value The value of the item to store, must be serializable.
34+
* @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
35+
* the driver supports TTL then the library may set a default value
36+
* for it or let the driver take care of that.
37+
*
38+
* @return bool True on success and false on failure.
39+
*/
40+
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
41+
42+
/**
43+
* Delete an item from the cache by its unique key.
44+
*
45+
* @param string $key The unique cache key of the item to delete.
46+
*
47+
* @return bool True if the item was successfully removed. False if there was an error.
48+
*/
49+
public function delete(string $key): bool;
50+
51+
/**
52+
* Wipes clean the entire cache's keys.
53+
*
54+
* @return bool True on success and false on failure.
55+
*/
56+
public function clear(): bool;
57+
58+
/**
59+
* Determines whether an item is present in the cache.
60+
*
61+
* @param string $key The unique cache key of the item to check for.
62+
*
63+
* @return bool True if the item is present in the cache, false otherwise.
64+
*/
65+
public function has(string $key): bool;
66+
67+
/**
68+
* Determines whether an item is missing from the cache.
69+
*
70+
* @param string $key The unique cache key of the item to check for.
71+
*
72+
* @return bool True if the item is missing from the cache, false otherwise.
73+
*/
74+
public function missing(string $key): bool;
75+
76+
/**
77+
* Creates a cache key based on provided parameters
78+
*
79+
* @param array $params Key parameters
80+
* @return string Generated cache key
81+
*/
82+
public function createKey(array $params): string;
83+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace ProcessMaker\Cache;
4+
5+
use Exception;
6+
use Illuminate\Support\Facades\Log;
7+
use Illuminate\Support\Facades\Redis;
8+
9+
abstract class CacheManagerBase
10+
{
11+
/**
12+
* The available cache connections.
13+
*
14+
* @var array
15+
*/
16+
protected const AVAILABLE_CONNECTIONS = ['redis', 'cache_settings'];
17+
18+
/**
19+
* Retrieve an array of cache keys that match a specific pattern.
20+
*
21+
* @param string $pattern The pattern to match.
22+
* @param string|null $connection The cache connection to use.
23+
*
24+
* @return array An array of cache keys that match the pattern.
25+
*/
26+
public function getKeysByPattern(string $pattern, string $connection = null, string $prefix = null): array
27+
{
28+
if (!$connection) {
29+
$connection = config('cache.default');
30+
}
31+
32+
if (!$prefix) {
33+
$prefix = config('cache.prefix');
34+
}
35+
36+
if (!in_array($connection, self::AVAILABLE_CONNECTIONS)) {
37+
throw new CacheManagerException('`getKeysByPattern` method only supports Redis connections.');
38+
}
39+
40+
try {
41+
// Get all keys
42+
$keys = Redis::connection($connection)->keys($prefix . '*');
43+
44+
// Filter keys by pattern
45+
return array_filter($keys, fn ($key) => preg_match('/' . $pattern . '/', $key));
46+
} catch (Exception $e) {
47+
Log::info('CacheManagerBase: ' . $e->getMessage());
48+
}
49+
50+
return [];
51+
}
52+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace ProcessMaker\Cache;
4+
5+
use Exception;
6+
7+
class CacheManagerException extends Exception
8+
{
9+
}

0 commit comments

Comments
 (0)