001package io.jboot.components.cache.support; 002 003import com.jfinal.captcha.Captcha; 004import com.jfinal.captcha.ICaptchaCache; 005import io.jboot.Jboot; 006import io.jboot.components.cache.JbootCacheManager; 007import io.jboot.utils.StrUtil; 008 009public class JbootCaptchaCache implements ICaptchaCache { 010 011 public static final String CACHE_NAME = "jboot_captchas"; 012 013 public JbootCaptchaCache() { 014 JbootCacheManager.me().getCache().addThreadCacheNamePrefixIngore(CACHE_NAME); 015 } 016 017 @Override 018 public void put(Captcha captcha) { 019 Jboot.getCache().put(CACHE_NAME, captcha.getKey(), captcha, (int) ((captcha.getExpireAt() - System.currentTimeMillis()) / 1000)); 020 } 021 022 @Override 023 public Captcha get(String key) { 024 return StrUtil.isBlank(key) ? null : Jboot.getCache().get(CACHE_NAME, key); 025 } 026 027 @Override 028 public void remove(String key) { 029 if (StrUtil.isNotBlank(key)) { 030 Jboot.getCache().remove(CACHE_NAME, key); 031 } 032 } 033 034 @Override 035 public void removeAll() { 036 Jboot.getCache().removeAll(CACHE_NAME); 037 } 038 039}