AppEngine Memcache expiration policies

前端 未结 1 642
青春惊慌失措
青春惊慌失措 2021-01-25 06:05

I was expecting the following AppEngine code:

MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
memcache.put(\"Foo\", \"Bar\", Expiration.o         


        
相关标签:
1条回答
  • 2021-01-25 06:31

    Wow! This was obscure, but I figure it out:

    Taking a look at the source for the doPut()-method in AsyncMemcacheServiceImpl.java, line 505 reads:

    itemBuilder.setExpirationTime(expires == null ? 0 : expires.getSecondsValue());
    

    And Expiration.getSecondsValue() contains the following line:

    return (int) (getMillisecondsValue() / 1000);
    

    In other words: An expiration value of "0" is equivalent to no expiration (same as null), and the expiration time is converted to seconds, by dividing by 1000.

    So, if I set an expiration of 1ms, it gets turned into 0 seconds (rounded down when divided by 1000), which is equivalent to no expiration... Blah!!!

    So, the answer is: Expiration.onDate(new Date(1000)) should expire immediately, unless the memcache server is still living in the 60's... :) Tried it. Works. Done...

    (These tests were done on the DevServer. I'm hoping that the production server will behave the same.)

    0 讨论(0)
提交回复
热议问题