How to set 12 hrs time format in apigee Cache

As I want to expire the cache twice a day. For example at both timings 8 AM and 8 PM. So is it possible to set the time format to 12 hrs instead of 24 hrs for apigee cache? so that the <TiimeOfDay> can be configured one time. also the documentation has not much details about the cache clearing twice a day. @Dino-at-Google

1 2 124
2 REPLIES 2

Not applicable

You can do one thing. You can invalidate cache explicitly at the particular time using an api call configured in cron in a system.

The way I would do what you describe:

I would compute the cache expiry time in a JavaScript , store it in a variable and then reference that variable in the TimeOfDay element.

for example

function getTimeString(s) {
  return s.substring(11, 19);
}
// return either 8am or 8pm, whichever is "next"
var then  = new Date();
then.setMinutes(0);
then.setSeconds(0);
then.setMilliseconds(0);
if (then.getHours()<8) {
  // 8 am TODAY is next
  then.setHours(8);
}
else if (then.getHours()<20) {
  // 8pm today is next
  then.setHours(20);
}
else {
  // 8am tomorrow is next
  then.setDate(then.getDate() + 1);
  then.setHours(8);
}
context.setVariable('desiredExpiry', getTimeString(then.toISOString()));

But you need to consider timezones. You said "8am" and "8pm", but ... relative to which timezone? The above code will choose the next 8am or 8pm in UCT. But that may not be what you mean when you say "8am". So adjust for your purposes, as necessary.

And then, configure your ExpirySettings like this.

<ExpirySettings>
    <TimeOfDay ref="desiredExpiry"/>
</ExpirySettings>