我正在使用doctrine 2.4开发symfony 2.5项目.
我想缓存查询结果的缓存ID和缓存时间,所以我可以删除缓存结果,只要管理员需要.
我能够使用"createQueryBuilder()"选项缓存查询结果.
例:
$this->createQueryBuilder('some_table')
->select('some_table')
->where('some_table.deleted_date IS NULL')
->getQuery()
->useResultCache(true)
->setResultCacheLifetime(120) //Query Cache lifetime
->setResultCacheId($queryCacheId) //Query Cache Id
->getResult();
Run Code Online (Sandbox Code Playgroud)
但我无法找到与"findOneBy()"选项的chache查询结果类似的方法.
例:
$this->findOneBy(array('some_field'=>$some_value));
Run Code Online (Sandbox Code Playgroud)
我正在寻找一些合适的解决方案,非常感谢任何帮助.
我必须从给定的整数序列中找到所有可能的解决方案,它等于给定的数字.
例如:1,2,3,4,5,6,7,8,9等于100回答:1 + 23 - 4 + 56 + 7 + 8 + 9 = 100
我的解决方案是示例25中的另一个总和:
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
$n = count($arr);
$sum = 25;
function checkSol() {
global $arr;
global $n;
global $sum;
$tempSum = 0;
for ($i = 0; $i < $n; $i++) {
$tempSum += $arr[$i];
}
if ($tempSum == $sum) {
for ($i = 0; $i < $n; $i++) {
if ($arr[$i] > 0) {
printf("+%d ", …Run Code Online (Sandbox Code Playgroud)