wu560130911 / hibernate-memcached

Automatically exported from code.google.com/p/hibernate-memcached
0 stars 0 forks source link

error expiry on DangaMemcache #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
- <exptime> is expiration time. If it's 0, the item never expires
  (although it may be deleted from the cache to make place for other
  items). If it's non-zero (either Unix time or offset in seconds from
  current time), it is guaranteed that clients will not be able to
  retrieve this item after the expiration time arrives (measured by
  server time).  

but you code is error
           Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.SECOND, cacheTimeSeconds);

            memcachedClient.set(key, o, calendar.getTime());

just send cacheTimeSeconds is ok

memcachedClient.set(key,o,new Date(cacheTimeSeconds*1l);

otherwise ,the object will not expire

Original issue reported on code.google.com by zheng...@gmail.com on 5 Jun 2009 at 2:28

GoogleCodeExporter commented 9 years ago
The current code is correct, please see the javadoc for the Whalin client...
http://tinyvh.com/Pz

The Date(long) constructor that you are using attempts to initialize a Date 
object to
the number of seconds past epoch. Which means that if cacheTimeSeconds equals 
5, your
code would create a Date object for 5 seconds past midnight Jan 1 1970.

The current code, though verbose because it uses the Calendar API, is correct. 
It
creates a Calendar initialized to now (no-arg Date is now). Then it dials the
calendar forward by cacheTimeSeconds (now + 5 seconds for example). It then 
gets out
a date (getTime() returns a Date) and sets that as the expiration time for the 
object.

Original comment by raykrue...@gmail.com on 5 Jun 2009 at 2:12

GoogleCodeExporter commented 9 years ago
but has you test on DangaMemcache?
I have tested it.
I'am report it because i found a error on this code.
I'am using memcached 1.2.0

Original comment by zheng...@gmail.com on 8 Jun 2009 at 1:48

GoogleCodeExporter commented 9 years ago
DangaMemcache is the Whalin client. Please look over the javadoc for that 
client as I
mentioned.

Original comment by raykrue...@gmail.com on 8 Jun 2009 at 10:53

GoogleCodeExporter commented 9 years ago
but the javadoc is error
i have read the DangeMemcache's source

may be you can read it some time

thanks

and this discuses was all over now.

Original comment by zheng...@gmail.com on 10 Jun 2009 at 2:36