FileCache.php 872 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\cache;
  3. class FileCache implements CacheInterface {
  4. private $name;
  5. public function __construct($cache_name) {
  6. $this->name = __DIR__ . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . $cache_name;
  7. }
  8. public function exist() {
  9. return file_exists($this->name);
  10. }
  11. public function get() {
  12. return unserialize(@file_get_contents($this->name));
  13. }
  14. public function remove() {
  15. @unlink($this->name);
  16. }
  17. public function save($data) {
  18. try{
  19. $data = serialize($data);
  20. } catch (\Exception $ex) {
  21. $data = serialize(\MGModule\DNSManager2\mgLibs\custom\helpers\SerializeXMLObject::getInstance($data)->refactor());
  22. }
  23. @file_put_contents($this->name, $data);
  24. }
  25. }