amoikevin / kitty-cache

Automatically exported from code.google.com/p/kitty-cache
0 stars 0 forks source link

Seconds or miliseconds #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In the code we can see the method put with 'seconds_to_store' value.

But here the 'seconds_to_store' value is added to miliseconds

/* --- code --- */
public void put(Object key, Object val, Integer seconds_to_store) {
        /* ... */
        seconds_to_store = seconds_to_store != null ? seconds_to_store : 9999999;
        cache.put(key, new Object[]{System.currentTimeMillis() + seconds_to_store, val});

Later, it is compared to miliseconds again

/* --- code --- */
    public Object get(Object key) {
        /* ... */
            Long expires = (Long) cache.get(key)[0];
            if (expires - System.currentTimeMillis() > 0) {

My 2cents. solution

public void put(Object key, Object val, Integer seconds_to_store) {
        /* ... */
        seconds_to_store =System.currentTimeMillis() + 1000L*(seconds_to_store != null ? seconds_to_store : 9999999);
        cache.put(key, new Object[]{seconds_to_store, val});

Other thing that can improve, no need to substract

/* --- code --- */
    public Object get(Object key) {
        /* ... */
            Long expires = (Long) cache.get(key)[0];
            if (expires > System.currentTimeMillis() ) {

Original issue reported on code.google.com by obe...@gmail.com on 17 Jun 2011 at 9:39

GoogleCodeExporter commented 8 years ago

Original comment by innovati...@gmail.com on 19 Dec 2011 at 6:49