Fix save item in cache

pull/4312/head
Angel Fernando Quiroz Campos 3 years ago
parent ca73e2fbdd
commit 7e6df1e544
  1. 28
      public/main/gradebook/lib/be/exerciselink.class.php

@ -342,7 +342,9 @@ class ExerciseLink extends AbstractLink
if (0 == $student_count) { if (0 == $student_count) {
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, null); $cacheItem = $cache->getItem($key);
$cacheItem->set(null);
$cache->save($cacheItem);
} }
return null; return null;
@ -351,17 +353,20 @@ class ExerciseLink extends AbstractLink
case 'best': case 'best':
$result = [$bestResult, $weight]; $result = [$bestResult, $weight];
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $result); $cacheItem = $cache->getItem($key);
$cacheItem->set($result);
$cache->save($cacheItem);
} }
return $result; return $result;
break;
case 'average': case 'average':
$count = count($this->getStudentList()); $count = count($this->getStudentList());
if (empty($count)) { if (empty($count)) {
$result = [0, $weight]; $result = [0, $weight];
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $result); $cacheItem = $cache->getItem($key);
$cacheItem->set($result);
$cache->save($cacheItem);
} }
return $result; return $result;
@ -370,27 +375,30 @@ class ExerciseLink extends AbstractLink
$result = [$sumResult / $count, $weight]; $result = [$sumResult / $count, $weight];
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $result); $cacheItem = $cache->getItem($key);
$cacheItem->set($result);
$cache->save($cacheItem);
} }
return $result; return $result;
break;
case 'ranking': case 'ranking':
$ranking = AbstractLink::getCurrentUserRanking($studentId, $students); $ranking = AbstractLink::getCurrentUserRanking($studentId, $students);
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $ranking); $cacheItem = $cache->getItem($key);
$cacheItem->set($ranking);
$cache->save($cacheItem);
} }
return $ranking; return $ranking;
break;
default: default:
$result = [$sum, $student_count]; $result = [$sum, $student_count];
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $result); $cacheItem = $cache->getItem($key);
$cacheItem->set($result);
$cache->save($cacheItem);
} }
return $result; return $result;
break;
} }
} }
} }

Loading…
Cancel
Save