• memercache 封装函数(原创)


    //最方便的获取缓存数据或者数据库数据的方法,只取第一行返回结果
    //先根据SQL语句,去缓存找,找不到,就执行数据库查询返回
    function GetFromCacheOrFetchRowOne ($sql, $db = null, $ttl = -1)
    {
    global $cache; //$cache变量永远只有一个,不需要多重定义的,所以不需以传参数的方式
    $key = 'SQL:'.md5($sql);
    if (! $rs = $cache->fetch($key)) {
    if (! $db) {
    global $db;
    if (! $db)
    global $dbConfig;
    $db = new DBMysqlClass();
    $db->connect($dbConfig['db']);
    }
    if (($rs = $db->fetchOne($sql)) !== false) {
    if ($ttl > 0)
    $cache->store($key, $rs, $ttl);
    else
    $cache->store($key, $rs);
    }
    }
    return $rs;
    }
    //最方便的获取缓存数据或者数据库数据的方法
    //先根据SQL语句,去缓存找,找不到,就执行数据库查询返回
    function GetFromCacheOrFetchRowSet ($sql, $db = null, $ttl = -1)
    {
    global $cache; //$cache变量永远只有一个,不需要多重定义的,所以不需以传参数的方式
    $key = 'SQL:'.md5($sql);
    if (! $rs = $cache->fetch($key)) {
    if (! $db) {
    global $db;
    if (! $db)
    global $dbConfig;
    $db = new DBMysqlClass();
    $db->connect($dbConfig['db']);
    }
    if (($rs = $db->fetchAll($sql)) !== false) {
    if ($ttl > 0)
    $cache->store($key, $rs, $ttl);
    else
    $cache->store($key, $rs);
    }
    }
    return $rs;
    }



  • 相关阅读:
    A Bayesian Approach to Deep Neural Network Adaptation with Applications to Robust Automatic Speech Recognition
    nnet3的代码分析
    Kaldi中的L2正则化
    HMM拓扑与转移模型
    Kaldi阅读并更改代码
    nnet3中的数据类型
    nnet3配置中的“编译”
    Kaldi的delta特征
    Kaldi的交叉熵正则化
    【搜索】 Prime Path
  • 原文地址:https://www.cnblogs.com/firmy/p/2310861.html
Copyright © 2020-2023  润新知