Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/00-Cache.php Secret

Created Jan 4, 2018
Embed
What would you like to do?
[OOP Interfaces] Object-Oriented Programming: Understanding Interfaces
<?php
class Cache
{
public function set($key, $value)
{
// method implementation
}
}
<?php
class Cache
{
public function set($key, $value) {
set_transient($key, $value);
}
}
<?php
interface iCache
{
public function set($key, $value);
public function get($key);
public function has($key);
}
<?php
interface iCache {
public function set($key, $value);
public function get($key);
public function has($key);
}
public class SimpleCache implemnents iCache
{
public function set($key, $value)
{
set_transient($key, $value, DAY_IN_SECONDS);
}
public function get($key)
{
if (!$this->has($key))
{
return false;
}
return get_transient($key);
}
public function has($key)
{
return false !== get_transient($key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.