Skip to content

Commit

Permalink
Update composer, refactor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkDvlp committed Dec 13, 2018
1 parent 15ae3fd commit c965071
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 151 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
nbproject/private/
composer.lock
nbproject/
vendor/
106 changes: 0 additions & 106 deletions FileCache.php

This file was deleted.

35 changes: 0 additions & 35 deletions MemoryCache.php

This file was deleted.

17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
"name": "vendor/simplePhpCache",
"description": "This very small lib is for caching in php apps.",
"name": "jtk/simplePhpCache",
"description": "Very small and simple lib for caching",
"keywords": ["cache", "filecache", "memorycache", "arraycache"],
"homepage": "http://github.com/jtkDvlp/simplePhpCache",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "JT Knabenschuh",
"name": "jtkDvlp",
"email": "jtkdevelopments@gmail.com"
}
],
"require": {}
"require": {
"php": ">=5.5.0"
},
"autoload": {
"psr-4": {"jtk\\simplePhpCache\\": "src"}
}
}
11 changes: 6 additions & 5 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
<?php
use jtk\simplePhpCache\FileCache;
use jtk\simplePhpCache\ArrayCache;

require_once('./FileCache.php');
require_once('./MemoryCache.php');
require __DIR__ . '/vendor/autoload.php';

session_start();

Expand Down Expand Up @@ -40,7 +41,7 @@ function example($cache)
mkdir('./cache/');
}

$filecache = new FileCache('./cache/', 50);
$filecache = new FileCache(__DIR__.'/cache/', 50);
//$cache->clear();
example($filecache);

Expand All @@ -54,7 +55,7 @@ function example($cache)
$_SESSION['cache'] = [];
}

$sessioncache = new MemoryCache(
$sessioncache = new ArrayCache(
$_SESSION['cache']);
//$cache->clear();
example($sessioncache);
Expand Down
49 changes: 49 additions & 0 deletions src/ArrayCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php namespace jtk\simplePhpCache;

class ArrayCache extends Cache
{
/** @var array */
private $array;


/**
* @param array $array
*/
public function __construct(&$array)
{
$this->array = &$array;
}

/**
* @param string $identifier
* @return mixed
*/
public function get($identifier)
{
return $this->array[$identifier];
}

/**
* @param string $identifier
* @return boolean
*/
public function has($identifier)
{
return isset($this->array[$identifier]);
}

/**
* @param string $identifier
* @param mixed $data
* @return mixed
*/
public function set($identifier, $data)
{
return $this->array[$identifier] = $data;
}

public function clear()
{
$this->array = [];
}
}
6 changes: 5 additions & 1 deletion Cache.php → src/Cache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php namespace jtk\simplePhpCache;

abstract class Cache
{
Expand All @@ -7,6 +7,10 @@ public abstract function has($identifier);
public abstract function set($identifier, $data);
public abstract function clear();

/**
* @param callable $func
* @return callable
*/
public function wrap($func)
{
return function() use ($func)
Expand Down
Loading

0 comments on commit c965071

Please sign in to comment.