Skip to content

Commit

Permalink
Adding namespacing and phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
cajogos committed Apr 2, 2017
1 parent 417a5f4 commit 0aeda95
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
9 changes: 3 additions & 6 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
composer.phar
/vendor/

# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
.idea/
vendor/
*.stackdump
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TempCache::remove($key);
```javascript
{
"require": {
"cajogos/php-temp-cache": "1.0.1"
"cajogos/php-temp-cache": "1.1"
}
}
```
Expand Down
47 changes: 46 additions & 1 deletion TempCache.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

namespace Cajogos;

/**
* Class TempCache
* @package Cajogos
*/
class TempCache
{
const TIME_5_MIN = 300;
Expand All @@ -11,8 +17,15 @@ class TempCache

const CACHE_FOLDER = '/tmp/php-temp-cache/';

/**
* @var bool
*/
private static $prepared = false;

/**
* @param string $key
* @return mixed|null
*/
public static function get($key)
{
if (self::prepare())
Expand All @@ -37,6 +50,12 @@ public static function get($key)
return null;
}

/**
* @param string $key
* @param string $value
* @param integer $expiry
* @return bool
*/
public static function put($key, $value, $expiry)
{
if (self::prepare())
Expand All @@ -50,13 +69,17 @@ public static function put($key, $value, $expiry)
'key' => $cache_key,
'expiry' => $expiry,
'value' => $serialized
);
);
$store = json_encode($store);
return self::save_cache_file($file, $store);
}
return false;
}

/**
* @param string $key
* @return bool
*/
public static function remove($key)
{
if (self::prepare())
Expand All @@ -68,6 +91,10 @@ public static function remove($key)
return false;
}

/**
* @param string $file
* @return bool|string
*/
private static function load_cache_file($file)
{
$file = self::CACHE_FOLDER . $file;
Expand All @@ -77,23 +104,41 @@ private static function load_cache_file($file)
}
return false;
}

/**
* @param string $file
* @param string $data
* @return bool
*/
private static function save_cache_file($file, $data)
{
$file = self::CACHE_FOLDER . $file;
return (!(file_put_contents($file, $data) === false));
}

/**
* @param string $file
* @return bool
*/
private static function delete_cache_file($file)
{
$file = self::CACHE_FOLDER . $file;
return unlink($file);
}

/**
* @param string $key
* @return string
*/
private static function cache_key_convert($key)
{
$key = 'tmpcache_' . $key;
return md5($key);
}

/**
* @return bool
*/
private static function prepare()
{
if (self::$prepared)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "Carlos Ferreira",
"email": "[email protected]",
"homepage": "http://ca.rlos.rocks",
"homepage": "https://carlos.fyi",
"role": "Developer"
}
],
Expand Down
1 change: 0 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0aeda95

Please sign in to comment.