-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add caching to reduce queries to the database and github
- Loading branch information
1 parent
dc09cfb
commit 3c7eaa9
Showing
8 changed files
with
160 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
---------------------------------- | ||
------ Created: 111724 ------ | ||
------ Austin Best ------ | ||
---------------------------------- | ||
*/ | ||
|
||
//-- BRING IN THE EXTRAS | ||
loadClassExtras('Cache'); | ||
|
||
class Cache | ||
{ | ||
public $cache; | ||
|
||
public function __construct() | ||
{ | ||
$this->init(); | ||
} | ||
|
||
public function __tostring() | ||
{ | ||
return 'Class loaded: Cache'; | ||
} | ||
|
||
public function init() | ||
{ | ||
$this->cache = new Memcached(); | ||
$this->cache->addServer('127.0.0.1', '11211') or die('Cache connection failure'); | ||
} | ||
|
||
public function set($key, $data, $seconds) | ||
{ | ||
if (!$this->cache) { | ||
$this->init(); | ||
} | ||
|
||
if ($key && $data && $seconds) { | ||
$this->cache->set($key, $data, $seconds); | ||
} | ||
} | ||
|
||
public function get($key) | ||
{ | ||
if (!$this->cache) { | ||
$this->init(); | ||
} | ||
|
||
if (!$key) { | ||
return; | ||
} | ||
|
||
return $this->cache->get($key); | ||
} | ||
|
||
public function bust($key) | ||
{ | ||
if (!$this->cache) { | ||
$this->init(); | ||
} | ||
|
||
if (!$key) { | ||
return; | ||
} | ||
|
||
$this->cache->delete($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters