Add Redis-based permission caching for users and subusers
- Introduced Redis-backed caching for user and subuser permission evaluations in the `route_t` trait, reducing database queries. - Enhanced `Redis` class with methods for permission caching: `cache_permission`, `get_permission`, and `clear_permission`. - Added test coverage for the new caching logic in `PermissionRedisCacheTest.php`. - Implemented Redis caching for authentication sessions with `cache_auth_session`, `get_auth_session`, and `clear_auth_session`. - Improved CORS handling for preflight requests in `index.php`.
This commit is contained in:
@@ -266,4 +266,50 @@ interface redis_i
|
||||
* @return self
|
||||
*/
|
||||
public function clear_customer_number_from_user_id(int $user_id): self;
|
||||
|
||||
/**
|
||||
* Cache an auth session payload for a given token
|
||||
* @param string $token
|
||||
* @param array $session
|
||||
* @param int $ttl Seconds to keep in cache
|
||||
* @return self
|
||||
*/
|
||||
public function cache_auth_session(string $token, array $session, int $ttl = 60): self;
|
||||
|
||||
/**
|
||||
* Get a cached auth session payload by token
|
||||
* @param string $token
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_auth_session(string $token): array|null;
|
||||
|
||||
/**
|
||||
* Clear a cached auth session payload by token
|
||||
* @param string $token
|
||||
* @return self
|
||||
*/
|
||||
public function clear_auth_session(string $token): self;
|
||||
|
||||
/**
|
||||
* Cache a permission evaluation
|
||||
* @param string $cache_key
|
||||
* @param bool $allowed
|
||||
* @param int $ttl
|
||||
* @return self
|
||||
*/
|
||||
public function cache_permission(string $cache_key, bool $allowed, int $ttl = 300): self;
|
||||
|
||||
/**
|
||||
* Get a cached permission evaluation
|
||||
* @param string $cache_key
|
||||
* @return bool|null
|
||||
*/
|
||||
public function get_permission(string $cache_key): bool|null;
|
||||
|
||||
/**
|
||||
* Clear a cached permission evaluation
|
||||
* @param string $cache_key
|
||||
* @return self
|
||||
*/
|
||||
public function clear_permission(string $cache_key): self;
|
||||
}
|
||||
Reference in New Issue
Block a user