Skip to content

Commit

Permalink
improve cache modularity (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur authored and davidcoutadeur committed Sep 16, 2024
1 parent 7ae0b13 commit 4f84c97
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 5 deletions.
37 changes: 36 additions & 1 deletion conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,42 @@
# Token lifetime in seconds
$token_lifetime = "3600";

## Cache
## File cache parameters

# cache type: File or Redis
$cache_type = "File";

# cache namespace: cache entries are grouped in this directory
$cache_namespace = "sspCache";

# cache directory: cache entries would be created in this extra
# directory inside namespace
$cache_directory = null;

# default lifetime for all cached entry
# not really usefull for now as each cache entry has a defined expiration
# (see cache_token_expiration and cache_form_expiration)
$cache_default_lifetime = 0;

## Redis cache parameters

# cache type: File or Redis
#$cache_type = "Redis";

# Data Source Name (DSN) for accessing to Redis server
# See https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html
#$cache_redis_url = "redis:user:password@?host[redis1:6379]&timeout=5&dbindex=0";

# cache namespace: cache entries are prefixed by this namespace
#$cache_namespace = "sspCache";

# default lifetime for all cached entries
# not really usefull for now as each cache entry has a defined expiration
# (see cache_token_expiration and cache_form_expiration)
#$cache_default_lifetime = 0;

## General cache parameters

# $cache_token_expiration: integer, duration in seconds of cached objects
# each time a token is involved
# (for example when sending a token by sms or by mail)
Expand Down
44 changes: 42 additions & 2 deletions docs/config_general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,49 @@ You can also integrate any other Captcha module by developping the corresponding
Cache
-----

self-service-password rely on Symfony cache libraries.
self-service-password relies on Symfony cache libraries.

You can define the cache expiration for some objects:
First you must choose your cache adapter: File or Redis.

Here are the parameters for File:

.. code-block:: php
# cache type: File or Redis
$cache_type = "File";
# cache namespace: cache entries are grouped in this directory
$cache_namespace = "sspCache";
# cache directory: cache entries would be created in this extra
# directory inside namespace
$cache_directory = null;
# default lifetime for all cached entries
# not really usefull for now as each cache entry has a defined expiration
# (see cache_token_expiration and cache_form_expiration)
$cache_default_lifetime = 0;
Here are the parameters for Redis:

.. code-block:: php
# cache type: File or Redis
$cache_type = "Redis";
# Data Source Name (DSN) for accessing to Redis server
# See https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html
$cache_redis_url = "redis:user:password@?host[redis1:6379]&timeout=5&dbindex=0";
# cache namespace: cache entries are prefixed by this namespace
$cache_namespace = "sspCache";
# default lifetime for all cached entries
# not really usefull for now as each cache entry has a defined expiration
# (see cache_token_expiration and cache_form_expiration)
$cache_default_lifetime = 0;
You can then define the general parameters for any cache:

.. code-block:: php
Expand Down
10 changes: 9 additions & 1 deletion docs/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Upgrade
From 1.6 to 1.7
---------------

If you have configured ``$token_lifetime`` parameter, for example for reset by sms or reset by mail features, you should verify that the duration is coherent with the new cache parameters, and adapt these parameters in your local configuration file if needed:
Cache configuration
~~~~~~~~~~~~~~~~~~~

A new cache system has been introduced in version 1.7 of Self-Service-Password. Your version will be automatically migrated to this new cache system, with a ``File`` adapter. You can also define a ``Redis`` adapter. New cache parameters in ``config.inc.php`` will work as they are, but you can adapt them if needed. See the :ref:`cache configuration<config_cache>` for more information.

If you have configured ``$token_lifetime`` parameter, for example for reset by sms or reset by mail features, you should verify that the duration is coherent with the new :ref:`cache parameters<config_cache>`, and adapt these parameters in your local configuration file if needed:

.. code-block:: php
Expand All @@ -19,6 +24,8 @@ If you have configured ``$token_lifetime`` parameter, for example for reset by s
# it is recommended to set a value high enough for a user to fill a form
$cache_form_expiration = 120;
New Dependencies
~~~~~~~~~~~~~~~~

New bundled dependencies have been added:

Expand All @@ -30,6 +37,7 @@ New bundled dependencies have been added:
* php-symfony-cache-contracts = v2.5.3
* php-psr-log = 1.1.4
* php-symfony-cache = v5.4.42
* php-predis-predis = v2.2.2


From 1.5 to 1.6
Expand Down
22 changes: 21 additions & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,27 @@
#==============================================================================
# Cache Config
#==============================================================================
$sspCache = new \Ltb\Cache( 'sspCache', 0, null );
$cache_class = '\\Ltb\\Cache\\'.$cache_type.'Cache';
switch($cache_type)
{
case "File":
$sspCache = new $cache_class( $cache_namespace,
$cache_default_lifetime,
$cache_directory
);
break;

case "Redis":
$sspCache = new $cache_class( $cache_redis_url,
$cache_namespace,
$cache_default_lifetime
);
break;

default:
error_log("Error: unknown cache type: $cache_type");
exit(1);
}

#==============================================================================
# Captcha Config
Expand Down
1 change: 1 addition & 0 deletions packaging/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Description: LDAP password change web interface
- php-symfony-cache-contracts = v2.5.3
- php-psr-log = 1.1.4
- php-symfony-cache = v5.4.42
- php-predis-predis = v2.2.2
1 change: 1 addition & 0 deletions packaging/rpm/SPECS/self-service-password.spec
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Provides: bundled(php-psr-cache) = 1.0.1
Provides: bundled(php-symfony-cache-contracts) = v2.5.3
Provides: bundled(php-psr-log) = 1.1.4
Provides: bundled(php-symfony-cache) = v5.4.42
Provides: bundled(php-predis-predis) = v2.2.2


%description
Expand Down

0 comments on commit 4f84c97

Please sign in to comment.