CrossPHP
  • Namespace
  • Class
  • Download

Namespaces

  • Cross
    • Auth
    • Cache
      • Driver
      • Request
    • Core
    • DB
      • Connecter
      • Drivers
      • SQLAssembler
    • Exception
    • Http
    • I
    • Lib
      • Document
    • Module
    • MVC
    • Runtime
  • None

Classes

  • Cross\Auth\CookieAuth
  • Cross\Auth\SessionAuth
  • Cross\Cache\Driver\FileCacheDriver
  • Cross\Cache\Driver\MemcacheDriver
  • Cross\Cache\Driver\RedisDriver
  • Cross\Cache\Request\FileCache
  • Cross\Cache\Request\Memcache
  • Cross\Cache\Request\RedisCache
  • Cross\Cache\RequestCache
  • Cross\Core\Annotate
  • Cross\Core\Application
  • Cross\Core\ArrayMap
  • Cross\Core\Config
  • Cross\Core\CrossArray
  • Cross\Core\Delegate
  • Cross\Core\FrameBase
  • Cross\Core\Helper
  • Cross\Core\HttpAuth
  • Cross\Core\Loader
  • Cross\Core\Rest
  • Cross\Core\Router
  • Cross\DB\Connecter\BaseConnecter
  • Cross\DB\Connecter\MySQLConnecter
  • Cross\DB\Connecter\PgSQLConnecter
  • Cross\DB\Connecter\SQLiteConnecter
  • Cross\DB\DBFactory
  • Cross\DB\Drivers\CouchDriver
  • Cross\DB\Drivers\MongoDriver
  • Cross\DB\Drivers\PDOSqlDriver
  • Cross\DB\SQLAssembler\MySQLAssembler
  • Cross\DB\SQLAssembler\PgSQLAssembler
  • Cross\DB\SQLAssembler\SQLAssembler
  • Cross\DB\SQLAssembler\SQLiteAssembler
  • Cross\Http\Request
  • Cross\Http\Response
  • Cross\Lib\Array2XML
  • Cross\Lib\Document\CallTree
  • Cross\Lib\Document\CallTreeToHTML
  • Cross\Lib\Document\HTML
  • Cross\Lib\StringToPHPStream
  • Cross\Module\SQLModule
  • Cross\MVC\Controller
  • Cross\MVC\Module
  • Cross\MVC\View
  • Cross\Runtime\ClosureContainer

Interfaces

  • Cross\I\CacheInterface
  • Cross\I\HttpAuthInterface
  • Cross\I\PDOConnecter
  • Cross\I\RequestCacheInterface
  • Cross\I\RouterInterface
  • Cross\I\SqlInterface

Exceptions

  • Cross\Exception\CacheException
  • Cross\Exception\CoreException
  • Cross\Exception\CrossException
  • Cross\Exception\FrontException

Functions

  • ascLogo
  • line
  • tBody
  • th
  • tHead
 1 <?php
 2 /**
 3  * Cross - a micro PHP 5 framework
 4  *
 5  * @link        http://www.crossphp.com
 6  * @license     MIT License
 7  */
 8 
 9 namespace Cross\Cache\Driver;
10 
11 use Cross\Exception\CoreException;
12 use Cross\I\CacheInterface;
13 
14 /**
15  * @author wonli <wonli@live.com>
16  * Class FileCacheDriver
17  * @package Cross\Cache\Driver
18  */
19 class FileCacheDriver implements CacheInterface
20 {
21     /**
22      * 缓存文件路径
23      *
24      * @var string
25      */
26     private $cache_path;
27 
28     function __construct($cache_path)
29     {
30         $cache_path = rtrim($cache_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
31         $this->cache_path = $cache_path;
32     }
33 
34     /**
35      * 返回缓存文件
36      *
37      * @param string $key
38      * @return mixed
39      */
40     function get($key = '')
41     {
42         $cache_file = $this->cache_path . $key;
43         if (!file_exists($cache_file)) {
44             return false;
45         }
46 
47         return file_get_contents($cache_file);
48     }
49 
50     /**
51      * 保存缓存
52      *
53      * @param string $key
54      * @param string $value
55      * @return mixed|void
56      * @throws CoreException
57      */
58     function set($key, $value)
59     {
60         $cacheFile = $this->cache_path . $key;
61         if (!file_exists($cacheFile)) {
62             $filePath = dirname($cacheFile);
63             if (!is_dir($filePath)) {
64                 $createDir = mkdir($filePath, 0755, true);
65                 if (!$createDir) {
66                     throw new CoreException('创建缓存目录失败');
67                 }
68             }
69         }
70 
71         file_put_contents($cacheFile, $value, LOCK_EX);
72     }
73 }
74 
CrossPHP API documentation generated by ApiGen