java获取缓存通用类

1

class JedisHelper {
    public static <T, R> T getBySecond(String cacheKey, int seconds, R p, Function<Object, T> function) {
        return function.apply(p);

    }

    public static <T> T getBySecond(String cacheKey, int seconds, Supplier<T> function) {
        return function.get();
    }
}

 

2.调用方法

 

 String value33 = JedisHelper.getBySecond("ad", 1, null, new Function<Object, String>() {
            @Override
            public String apply(Object o) {
                return "ccc";
            }
        });

        String prefix = "a";
        String value34 = JedisHelper.getBySecond("ad", 1, prefix, new Function<Object, String>() {
            @Override
            public String apply(Object o) {
                return prefix + "ccc";
            }
        });


        String value35 = JedisHelper.getBySecond("ad", 1, () -> {
            return prefix + "ccc";
        });

 

posted @ 2017-11-17 15:38  zslm___  阅读(871)  评论(0编辑  收藏  举报