Skip to content

Commit

Permalink
setPath
Browse files Browse the repository at this point in the history
  • Loading branch information
shabeer-ali-m committed Jul 9, 2021
1 parent 5a1040b commit 79c776e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ echo sCache::cache('myKey')->get();
By default the cache will save in `tmp` folder. Please make sure that the `tmp` folder have write access.
You can set custom folder for cache
```php
sCache::setPath('youfolder/tempfolder/');
```
or
```php
define('SuperCache_PATH','youfolder/tempfolder/');
```


#### Advanced Options
##### Locking

Expand Down
39 changes: 39 additions & 0 deletions src/SuperCache/SuperCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class SuperCache
*/
static $static_path = 'tmp/';

/**
* @var bolean
*/
static $is_pretty = true;

/**
* @var string
*/
Expand Down Expand Up @@ -103,6 +108,33 @@ public static function cache($key)
return self::$instance[$key];
}

/**
* Set File Path
* @param [sting] $path file path
*/
public static function setPath($path)
{
self::$static_path = $path;
}

/**
* Get File Path
* @return [sting] $path file path
*/
public static function getPath()
{
return self::$static_path;
}

/**
*
* @param [bolean] $flag
*/
public static function setPretty($val)
{
self::$is_pretty = (boolean) $val;
}

/**
* Saving cache
* @param [mixed] $val Cache Value
Expand All @@ -116,6 +148,13 @@ public function set($val)
}

$val = var_export($val, true);

//is_pretty
if (!self::$is_pretty) {
$val = str_replace(["\n",", '"," => "],["",",'","=>"], $val);
}


// HHVM fails at __set_state, so just use object cast for now
$val = str_replace('stdClass::__set_state', '(object)', $val);
// Write to temp file first to ensure atomicity
Expand Down

0 comments on commit 79c776e

Please sign in to comment.