Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow to dynamically provide TTL configuration #2587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Koooooo-7 wants to merge 5 commits into spring-projects:main from Koooooo-7:ttl

Conversation

Copy link
Contributor

@Koooooo-7 Koooooo-7 commented May 24, 2023
edited
Loading

Fix issue: #1433 .

Give users a chance to change the ttl dynamically and give them the flexibility to do so.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a context-less supplier doesn't add much value here. I could well think of a case, where the TTL could be computed from the actual object.

How about a design of a TTL function (Function<Object, Duration>) where the object argument is provided by the actual cache value?

Koooooo-7 reacted with thumbs up emoji
private final ConversionService conversionService;

private final Durationttl;
private final Supplier<Duration> ttlProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Supplier doesn't make much sense as it just defers the decision on TTL without adding much contextual value.

@mp911de mp911de self-assigned this May 25, 2023
Copy link
Contributor Author

Koooooo-7 commented May 26, 2023
edited
Loading

Hi @mp911de , I agree with that we should provide some context for user to get the ttl and I did the updates.
And the changes:

  1. For now I provide the original key and value to users instead of createAndConvertCacheKey.
  2. About the public Duration getTtl() {} for backward compatibility, I user the Object.class as the default key instead.

@mp911de mp911de changed the title (削除) Allow to dynamically provide TTL configuration. (削除ここまで) (追記) Allow to dynamically provide TTL configuration (追記ここまで) May 26, 2023
mp911de pushed a commit that referenced this pull request May 26, 2023
We now support a TtlFunction to compute the time to live for cache entries.
Closes #1433
Original pull request: #2587 
mp911de added a commit that referenced this pull request May 26, 2023
Replace BiFunction with TtlFunction for a more concise definition. Deprecate RedisCacheConfiguration.getTtl in favor of Ttlfunction.
Enhance tests.
See #1433
Original pull request: #2587 
@mp911de mp911de added in: cache RedisCache and CacheManager type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 26, 2023
Copy link
Member

mp911de commented May 26, 2023

Thank you for your contribution. That's merged and polished now.

Koooooo-7 reacted with heart emoji

jxblum pushed a commit to jxblum/spring-data-redis that referenced this pull request Jun 8, 2023
We now support a TtlFunction to compute the time to live for cache entries.
Closes spring-projects#1433
Original pull request: spring-projects#2587 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@mp911de mp911de Awaiting requested review from mp911de

Labels
in: cache RedisCache and CacheManager type: enhancement A general enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add TtlFunction to RedisCacheConfiguration for dynamic Time to Live

AltStyle によって変換されたページ (->オリジナル) /