Async expiration update ( Touch ) with over 30 days, is it supported?

Hi, I want to update expiry async,
but I can’t find the needed api

usual API is smth like .touch(key, 90, 90L, TimeUnit.DAYS))

but such signature is not available via
Observable.from(keys)
.flatMap(key -> this.getBucket().async().touch(key, defaultExpiry))
.subscribe();

only with Int value.

Hi Ekaterina,

For the async method that takes an int, if the value is less than the number of seconds in 30 days then it’s treated as a duration in seconds. If it the value is greater, it’s interpreted as an absolute Unix timestamp (seconds since January 1, 1970).

A 90 day timeout can be expressed as:

int expiration = (int) MILLISECONDS.toSeconds(
    System.currentTimeMillis() + DAYS.toMillis(90));

I don’t know the history of why the sync and async APIs differ, but there’s more discussion in this other thread:

2 Likes

1800ms = 30 minutes, 2592000000ms = 3 months, 90 - in days

so , you mean
if I use touch(id, 1800)
then expiry will be 30 minutes

and if I want to use time over 30 days, for example 90 days, then
int expiration = (int) MILLISECONDS.toSeconds(
System.currentTimeMillis() + DAYS.toMillis(90));
touch(id, 1544738356)
?

But this value is to big for int type. for example I’ve tried to set
touch(id, 2592000000) ( as 90 days in ms ) and I’ve got an error that value is to big for Integer type.

Hi Ekaterina,

so , you mean
if I use touch(id, 1800)
then expiry will be 30 minutes

Yes.

and if I want to use time over 30 days, for example 90 days, then
int expiration = (int) MILLISECONDS.toSeconds(
System.currentTimeMillis() + DAYS.toMillis(90));
touch(id, 1544738356)
?

If you mean touch(id, expiration), then yes.

But this value is to big for int type. for example I’ve tried to set
touch(id, 2592000000) ( as 90 days in ms ) and I’ve got an error that value is to big for Integer type.

The expiration value should not be 90 days in ms. The value you want is “The current time in seconds, plus 90 days in seconds”. If you prefer to think of it that way, an equivalent expression is:

int expiration = (int) (MILLISECONDS.toSeconds(System.currentTimeMillis())
        + DAYS.toSeconds(90));

Yes, there is the potential for integer overflow if the expiration is far enough in the future (see: year 2038 problem), but 90 days from September 14, 2018 is something like 1544739782 which fits in a signed integer just fine.

1 Like

Hi,
I want to keep the document for longer time and it might be beyond 2038.
How should I handle this now as the timestamp in second exceeds the maximum integer value?

Thanks,
Amiya