Skip to content

Support an @Expiry, @Expiration or @TTL annotation #1060

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
aaronjwhiteside opened this issue Jan 21, 2021 · 3 comments · Fixed by #1188
Closed

Support an @Expiry, @Expiration or @TTL annotation #1060

aaronjwhiteside opened this issue Jan 21, 2021 · 3 comments · Fixed by #1188
Labels
type: enhancement A general enhancement

Comments

@aaronjwhiteside
Copy link
Contributor

Just like we have @Field @Id and @Version support, it would be good to have a field to read the document expiry value from.

This field should support being of the type int, long, Duration and some subset of classes from java.time.*.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 21, 2021
@aaronjwhiteside aaronjwhiteside changed the title Support an @Expiry or @TTL annotation Support an @Expiry, @Expiration or @TTL annotation Jan 28, 2021
@aaronjwhiteside
Copy link
Contributor Author

Being able to annotate a field to nominate it as containing the expiry value would also allow programmatic control of expiry when using a Repository.

User user = new User();
user.setExpiry(Duration.ofHours(1));
userRepository.save(user);

Analogous to:

template.insertById(User.class)
   .withExpiry(Duration.ofHours(1))
   .one(user);

@mikereiche mikereiche added type: enhancement A general enhancement status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 3, 2021
@mikereiche
Copy link
Collaborator

mikereiche commented Aug 10, 2021

Should be supported with #1149 in org.springframework.data:spring-data-couchbase:4.3.0-M2 by:

public interface UserRepository extends CouchbaseRepository<User, String>, DynamicProxyable<UserRepository> {...}
userRepository.withOptions(InsertOptions.insertOptions().expiry(Duration.ofHours(1)).save(user);

@aaronjwhiteside
Copy link
Contributor Author

aaronjwhiteside commented Nov 18, 2021

userRepository.withOptions(InsertOptions.insertOptions().expiry(Duration.ofHours(1)).save(user);

So if the entity already has a field annotated with @Expiration, what is the purpose of specifying the expiry via options? Shouldn't we just read the value of the field? There is a lack of symmetry here...

Then there is also the issue of type conversion, what types does @Expiration support?

I see long being tested in the PR, but it would be nice if it supported things like Instant and Duration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants