• 随便说说
  • 读源码时候发现cacheStore并没有作用啊

按道理说,缓存的设置不应该是随着数据库更新自动更新吗,保持数据一致。但是并没有找到同步更新的代码。
cacheStore在Option模块中用于缓存系统属性,但是只缓存了"options"这一个字段(代表Option所有信息),
并不能通过某一个key获取到某个option值,为什么要这么做。我所理解缓存应该是一个通过缓存缓存具体的每一个option到cacheStore,然后在需要使用option的模块直接从cacheStore中拿到option值,然后还要具有和数据库同步的能力。
但是项目源码中没有体现,请问为什么,是我没有读懂代码吗,请指正,十分感谢!
String OPTIONS_KEY = "options";

 public Map<String, Object> listOptions() {
        // Get options from cache
        return cacheStore.getAny(OPTIONS_KEY, Map.class).orElseGet(() -> {
            List<Option> options = listAll();

            Set<String> keys = ServiceUtils.fetchProperty(options, Option::getKey);

            Map<String, Object> userDefinedOptionMap = ServiceUtils.convertToMap(options, Option::getKey, option -> {
                String key = option.getKey();

                PropertyEnum propertyEnum = propertyEnumMap.get(key);

                if (propertyEnum == null) {
                    return option.getValue();
                }

                return PropertyEnum.convertTo(option.getValue(), propertyEnum);
            });

            Map<String, Object> result = new HashMap<>(userDefinedOptionMap);

            // Add default property
            propertyEnumMap.keySet()
                    .stream()
                    .filter(key -> !keys.contains(key))
                    .forEach(key -> {
                        PropertyEnum propertyEnum = propertyEnumMap.get(key);

                        if (StringUtils.isBlank(propertyEnum.defaultValue())) {
                            return;
                        }

                        result.put(key, PropertyEnum.convertTo(propertyEnum.defaultValue(), propertyEnum));
                    });

            // Cache the result
            cacheStore.putAny(OPTIONS_KEY, result);

            return result;
        });
    }