业务经理

微信扫描以上二维码

028-61286886

技术咨询

自定义函数怎么写入读取缓存

开源系统 更新 2020-11-24 17:39:02 胡银萍

image.png

自定义函数 写入读取缓存,代码如上图,一直进入if内,大佬看看哪里有错,if内data有值

方案

  • 一休哥 #1 · 2019-09-16 21:25:21
    后台没开启缓存么
  • 胡银萍 #2 · 2019-09-17 08:50:23
    一休哥 后台开启了缓存功能,还是一样的
  • 二开/定制/使用解答专家 #3 · 2019-09-17 09:10:07
    我的可以缓存,这个本来就是缓存函数
  • 胡银萍 #4 · 2019-09-17 09:13:12
    二开/定制/使用解答专家 每次运行都会 echo ‘---’ 这个代码不是在 if 里面吗,意思是每次都进 if 吗?
  • 二开/定制/使用解答专家 #5 · 2019-09-17 09:47:09
    满意答案
    只能说明你data本身就是空的
  • 胡银萍 #6 · 2019-09-17 09:58:31
    二开/定制/使用解答专家 function vg_price($num){ $ci = &get_instance(); $name = 'ym-'.$num; $data = $ci->get_cache_data($name); if (!$data) { echo "---"; $url = 'http://222.75.151.210:8085/webService/BaseManage/CORN_PRICE.asmx';; //接收xml数据的文件 $header[] = "Content-type: text/xml; charset=utf-8"; //定义content-type为xml,注意是数组 $xmlData = ' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:tem="http://tempuri.org/">; <soapenv:Header/> <soapenv:Body> <tem:getPrice> <tem:code>'.$num.'</tem:code> </tem:getPrice> </soapenv:Body> </soapenv:Envelope> '; $ch = curl_init ($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlData); $response = curl_exec($ch); if(curl_errno($ch)){ printcurl_error($ch); } curl_close($ch); $data = strip_tags($response); $ci->set_cache_data($name, $data, 3600); } return $data;}您测试一下 参数为 1001
  • 扫地僧 #7 · 2019-09-17 10:16:24
    function vg_price($num){
        $ci = &get_instance();
        $name = 'ym-'.$num;
        $data = $ci->get_cache_data($name);
        if (!$data) {
            echo "---";
            
            $data = 'test2123123123';
            $ci->set_cache_data($name, $data, 3600);
        }
        return $data;
    }
    这还不简单的测试,如果任然进入if,就是系统没有开启缓存,或者cache权限不对
  • 胡银萍 #8 · 2019-09-17 11:24:14
    扫地僧
    image.png

    image.png
  • 胡银萍 #9 · 2019-09-17 11:24:48
    多次访问一直都是这样
  • 长沙小陈 #10 · 2019-09-17 12:00:41
    我的经验,1cache/file和cache/data能否可写文件,2插件优化里面是不是文件存储缓存,3实在不行就检查下程序版本是不是最新
  • 胡银萍 #11 · 2020-11-24 17:39:02
    @二开/定制/使用解答专家:1111111111111111

迅睿系统漏洞

站群分站系统
站群分站系统(2026-10-15)
子站域名新增llms.txt访问
GEO系统
GEO系统(2026-10-14)
修复下载zip空白地址问题 修复流量复刻和任务队列错误
GeoSeo收录宝
GeoSeo收录宝(2026-10-14)
新增 站长工具箱 前端首页自动调用meta 数据
滑块验证码 Gocaptcha
滑块验证码 Gocaptcha(2026-10-13)
基于开源项目 go-captcha 的行为验证码插件,滑动拼图、区域...
GeoSeo工具箱
GeoSeo工具箱(2026-10-13)
优化巡检任务
GeoSeo排名助手
GeoSeo排名助手(2026-10-11)
加入大模型自定义
SEO聚合关键字
SEO聚合关键字(2026-10-11)
优化关键字列表页最多支持1万篇文章,过多会导致服务器扛不住;
CMS内容同步复制
CMS内容同步复制(2026-10-10)
增加时间是否更新的开关