Skip to content

Provide a way to disable cleanup cron #1159

Closed
@saiya

Description

@saiya

Hi, I want a way to disable cleanup cron in Spring Session Data Redis (as described in previous conversation: #1119 (comment) ).

Here is a issue that describes about the matter.

TL;DR

  • Sometime user want to disable cleanup cron of Spring Session Data Redis and Spring Session JDBC
  • There was a known workaround to set cleanup-cron=0 0 5 31 2 (February 31st, never comes), but it does not work with recent version of spring-context
  • It is difficult to override RedisHttpSessionConfiguration and JdbcHttpSessionConfiguration to prevent cleanup cron.
  • What I want is a way to disable cleanup cron. And also enable to use property placeholder in cleanupCron attribute.

Motivation

I want to disable cleanup cron because ...

  • use case 1) When I have many web servers, I want to enable cleanup-cron on only one server and want to disable cleanup-cron on other servers to reduce DataStore load and connection pool usage.
  • use case 2) When SessionDeletedEvent and SessionExpiredEvent seem not to be needed (also no need to close WebSocket connections associated with the session), I want to disable cleanup-cron entirely.

Limitation of current implementation

As shown in example code of #1119 (comment), current RedisHttpSessionConfiguration and JdbcHttpSessionConfiguration does not formal way to disable cleanup cron.

My understanding is that above example code is a only way currently and such way is poor in maintainability.

What I want

My proposal is to add following attributes to disable cleanup cron:

  • Add boolean enableCleanupCron = true optional attribute into @EnableRedisHttpSession and @EnableJdbcHttpSession
    • Default value is true, it is same with existing behavior
    • When it is false, RedisHttpSessionConfiguration and JdbcHttpSessionConfiguration will not register CronTask
  • Enable to use property placeholder in disableCleanupCron and cleanupCron attributes
    • As described in use case A, sometimes user want to vary cleanup cron setting by environment.
    • Use StringValueResolver to resolve placeholders seems to be a way to resolve placeholders (current implementation uses it on redisNamespace attribute but not on cleanupCron).
    • Current cleanupCron attribute seems to accept only cron form (e.g. 0 0 5 31 2). Thus introducing StringValueResolver is not breaking change in my understanding.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions