Simple implementation of LRU caching in PHP This is my implementation of LRU caching in PHP. 

It works fine when I tested as. What are the things that I miss or need attention?

&lt;?php

class Cache{
    private $cache;
    private $size;

    public function __construct($size)
    {
        $this-&gt;cache = [];
        $this-&gt;size = $size;
    }

    public function put($item)
    {
        if($this-&gt;isFull())
        {
            if(in_array($item, $this-&gt;cache))
            {
                $this-&gt;cache = array_diff($this-&gt;cache, [$item]);
            }
            else
            {
                array_pop($this-&gt;cache);
            }
        } 

        array_unshift($this-&gt;cache,$item); 
    }

    public function display()
    {
        var_dump($this-&gt;cache);
    }

    private function isFull()
    {
        if(count($this-&gt;cache) &gt;= $this-&gt;size)
        {
            return true;
        } 
    }
}

$cache_size = 4;
$entries = [3,4,4,5,6,7,4,4,3,5,2,3,1,1,4];

$cache = new Cache($cache_size);
$cache-&gt;display();

foreach($entries as $entry)
{
    $cache-&gt;put($entry);
}

$cache-&gt;display();


Output for above provided data

//blank cache
array(0) {
}
//insertion of all entries
array(4) {
  [0]=&gt;
  int(4)
  [1]=&gt;
  int(1)
  [2]=&gt;
  int(3)
  [3]=&gt;
  int(2)
}
This implementation is quite simple. I compared it with some others in PHP as well as other languages like C++, Java and JavaScript. Some use a node class to store a key and value separately (e.g. this PHP implementation) but for a simple implementation your approach seems fine. 

I noticed that the method isFull() only explicitly returns a value when true is returned. While it works because the conditional that calls that method would this implicitly evaluate the empty return to a false-y  value, some would argue that methods that return a value should do so in every case, for the sake of readability. That could be achieved by simply returning the conditional:

private function isFull()
{
    return count($this-&gt;cache) &gt;= $this-&gt;size);
}


And one other simplification would be to set the property/instance variable $cache to an empty array when it is declared, since it can be evaluated at compile time and does not depend on any run-time information to be evaluated, instead of inside the constructor:

private $cache = [];