Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

存入的value为啥有一些乱码 #934

Open
starslink opened this issue Oct 18, 2024 · 5 comments
Open

存入的value为啥有一些乱码 #934

starslink opened this issue Oct 18, 2024 · 5 comments

Comments

@starslink
Copy link

starslink commented Oct 18, 2024

QuickConfig qc = QuickConfig.newBuilder(SHOP_ITEM_LACK_LOCAL)
      // 24 小时过期
      .expire(Duration.ofHours(24))
      .localExpire(Duration.ofHours(24))
      .localLimit(Integer.MAX_VALUE)
      .cacheType(CacheType.BOTH)
      .valueEncoder(Fastjson2ValueEncoder.INSTANCE)
      .valueDecoder(Fastjson2ValueDecoder.INSTANCE)
      // 本地通知过期
      .syncLocal(true)
      .build();
    shopItemLackCache = cacheManager.getOrCreateCache(qc);
@PostMapping("/post")
  public String post(@RequestBody A a) {
    shopItemLackCache.put("AX", a);
    return "ok";
  }

  static class A {

    private String x;

    private String y;

    public A() {
    }

    public A(String x, String y) {
      this.x = x;
      this.y = y;
    }

    public String getX() {
      return x;
    }

    public void setX(String x) {
      this.x = x;
    }

    public String getY() {
      return y;
    }

    public void setY(String y) {
      this.y = y;
    }
  }

一个简单的POST请求:

image
  • 存入的值为:
    ����#com.alicp.jetcache.CacheValueHolder7{"accessTime":1729242058279,"expireTime":1729328458279}1com.example.testinit.controller.CacheController$A�{"x":"123","y":"xxxx"}
@areyouok
Copy link
Collaborator

有额外的元信息

@starslink
Copy link
Author

[
    {
        "@type": "com.xxxx.oms.domain.base.DataDictItem",
        "createdTime": "2023-04-11T09:13:19",
        "dataDictId": 16274017971061760,
        "dataDictItemCode": "test",
        "dataDictItemExtendName": "红灯打开",
        "dataDictItemExtendName1": "red-on",
        "dataDictItemExtendName2": "1",
        "dataDictItemId": 16274024014480384,
        "dataDictItemName": "扫描提醒哦",
        "modifiedTime": "2024-02-26T15:04:13",
        "system": false
    },
    {
        "@type": "com.xxxx.oms.domain.base.DataDictItem",
        "createdTime": "2023-04-12T15:02:50",
        "dataDictId": 16274017971061760,
        "dataDictItemCode": "test1",
        "dataDictItemId": 16275783180272640,
        "dataDictItemName": "测试1",
        "modifiedTime": "2023-04-12T15:02:50",
        "system": false
    }
]

为啥不是这样显示呢

@areyouok
Copy link
Collaborator

你不能只顾自己需要的数据,框架也需要额外的数据

@starslink
Copy link
Author

starslink commented Oct 22, 2024

我知道您的意思,我的意思是CacheValueHolder能不能也格式化存储

例如这样

{
    "type": "@com.alicp.jetcache.CacheValueHolder",
    "expireTime": 12323434,
    "accessTime": 123123213,
    "value": {
        "type": {
            "@type": "com.xxxx.oms.domain.base.DataDictItem",
            "createdTime": "2023-04-12T15:02:50",
            "dataDictId": 16274017971061760,
            "dataDictItemCode": "test1",
            "dataDictItemId": 16275783180272640,
            "dataDictItemName": "测试1",
            "modifiedTime": "2023-04-12T15:02:50",
            "system": false
        }
    }
}

@areyouok
Copy link
Collaborator

不光是CacheValueHolder,还有别的信息,首先最重要的信息是编码方式(比如描述这条数据是json编码方式),放在最前面。

这不可能改了,改了就兼容,如果你觉得有必要,就得自己改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants