donglu7816 2016-06-24 10:33
浏览 555

如何在golang中进行持久缓存?

I am creating a command line utility using go , which will request particular server for data and will get the data from server in JSON response. Utility can do multiple requests for multiple products . I am able to do multiple requests and get the response for each product properly in JSON format. Now , I want to save the result locally in caching or local files. By which on every request I will check the local cache before sending request to server . If data is available for that product then no request will be send .

I want to save the whole json response in cache or local file and keep that data every time before doing any request to server for data.

Use Case : Products {"A","B","C","D","E"} It could be any number of products Test 1 : Get data for A,B,C Check local storage whether data is available or do request. Save json request in storage for each product.

So for test 1 ,It will have entry like: [{test 1 : [{product a : json response} , {product b : json response} ,{product c : json response}]}]

And in case if test fails in between and it get results for two products it should save response for 2 products and if we reran the test it will get result for 3rd product only.

  • 写回答

2条回答 默认 最新

  • douyigua5381 2016-06-24 10:52
    关注

    You can store the data inside a Map and get it via Key, you can implement it or use plugin such as go-cache.
    As alternative you can use Redis for storing the data, here you can find the driver for Go

    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘