Skip to content

Commit

Permalink
Use an associative array to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2018
1 parent 6ec01eb commit 98aafb4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Cache/Engine/ArrayEngine.php
Expand Up @@ -31,7 +31,7 @@ class ArrayEngine extends CacheEngine
/**
* Cached data.
*
* Structured as [key => [expiration, value]]
* Structured as [key => [exp => expiration, val => value]]
*
* @var array
*/
Expand All @@ -48,7 +48,7 @@ public function write($key, $value)
{
$key = $this->_key($key);
$expires = time() + $this->_config['duration'];
$this->data[$key] = [$expires, $value];
$this->data[$key] = ['exp' => $expires, 'val' => $value];

return true;
}
Expand All @@ -70,13 +70,13 @@ public function read($key)

// Check expiration
$now = time();
if ($data[0] <= $now) {
if ($data['exp'] <= $now) {
unset($this->data[$key]);

return false;
}

return $data[1];
return $data['val'];
}

/**
Expand All @@ -92,9 +92,9 @@ public function increment($key, $offset = 1)
$this->write($key, 0);
}
$key = $this->_key($key);
$this->data[$key][1] += $offset;
$this->data[$key]['val'] += $offset;

return $this->data[$key][1];
return $this->data[$key]['val'];
}

/**
Expand All @@ -110,9 +110,9 @@ public function decrement($key, $offset = 1)
$this->write($key, 0);
}
$key = $this->_key($key);
$this->data[$key][1] -= $offset;
$this->data[$key]['val'] -= $offset;

return $this->data[$key][1];
return $this->data[$key]['val'];
}

/**
Expand Down Expand Up @@ -155,9 +155,9 @@ public function groups()
foreach ($this->_config['groups'] as $group) {
$key = $this->_config['prefix'] . $group;
if (!isset($this->data[$key])) {
$this->data[$key] = [PHP_INT_MAX, 1];
$this->data[$key] = ['exp' => PHP_INT_MAX, 'val' => 1];
}
$value = $this->data[$key][1];
$value = $this->data[$key]['val'];
$result[] = $group . $value;
}

Expand All @@ -175,7 +175,7 @@ public function clearGroup($group)
{
$key = $this->_config['prefix'] . $group;
if (isset($this->data[$key])) {
$this->data[$key][1] += 1;
$this->data[$key]['val'] += 1;
}

return true;
Expand Down

0 comments on commit 98aafb4

Please sign in to comment.