Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .gitattributes

This file was deleted.

216 changes: 2 additions & 214 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,215 +1,3 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg
vendor/
composer.lock
85 changes: 76 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
PHP Cache Class (File base)
PHP FileCache Class (File base)
============================
A simple file based cache based from Erik Giberti's FileCache class. See [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)

## Enhanced Features

* Data is serialized and JSON encoded
* Cache data is encrypted by `mcrypt`
* File Based Cache was explained [here](http://af-design.com/blog/2010/07/30/simple-file-based-caching-in-php/)

## Installation

Run the following command in your command line shell in your php project

```sh
$ composer require rothkj1022/php-cache-class
```

Done.

You may also edit composer.json manually then perform ```composer update```:

```
"require": {
"rothkj1022/php-cache-class": "^2.1.0"
}
```

## Getting started

### Example usage with composer

```php
//load composer packages
require('vendor/autoload.php');

//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");
```

### Example usage without composer

```php
//require the class
require_once("lib/class.cache.php");
require_once("lib/FileCache.php");

//create new instance of the class
$cache = new Cache("tmp/");
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");

//...
```

## Sample Call
### Local file source example

```php
$cache_key = "client_list";

Expand All @@ -29,37 +64,69 @@ if (!$clients_data = $cache->get($cache_key)) {

//set the cache up!
$expire = 3600; //1 hour
$cache->set($cache_key, $clients_data, $expire);
$cache->set($cache_key, $clients_data, $expire);
}

var_dump($clients_data);
```

### External http GET request example
```php
$uri = 'https://raw.githubusercontent.com/bahamas10/css-color-names/master/css-color-names.json';
$remote_data = $cache->file_get_contents($uri);
var_dump($remote_data);
```

## Reference

Code reference for you to get started!

### Properties

* `protected $root = '/tmp/';` - Value is pre-pended to the cache, should be the full path to the directory.
* `protected $error = null;` - For holding any error messages that may have been raised
* `private $_encryption_key = 'Fil3C@ch33ncryptionK3y'` - Main key used for encryption (you need to set this up inside the class)

### Methods

#### Public Methods

* `Cache::get($key)` - Reads the data from the cache specified by the cache key
* `Cache::set($key [, $data, $ttl])` - Saves data to the cache. Anything that evaluates to false, null, '', boolean false, 0 will not be saved. `$ttl` Specifies the expiry time
* `Cache::delete($key)` - Deletes the cache specified by the `$key`
* `Cache::get_error()` - Reads and clears the internal error
* `Cache::have_error()` - Can be used to inspect internal error

#### Private Methods
See code to see all private methods used like `Cahce::_encrypt($pure_string)` etc.

## Feedback
All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at [www.lodev09.com](http://www.lodev09.com "www.lodev09.com") or email me at [lodev09@gmail.com](mailto:lodev09@gmail.com)
See code to see all private methods used like `Cache::_encrypt($pure_string)` etc.

## Changelog

### Version 2.1.3

* Fixed: Stopped echoing guzzle request errors to screen

### Version 2.1.2

* Integrated guzzle for more efficient http get requests

### Version 2.1.1

* Changed: Renamed class back to Erik Giberti's original name, FileCache

### Version 2.1.0

* Added: Composer integration
* Added: changelog

## Credits
© 2011-2014 - Coded by Jovanni Lo / [@lodev09](http://twitter.com/lodev09)

2010 - Authored by Erik Giberti
2011-2014 - Rewritten by Jovanni Lo / [@lodev09](https://twitter.com/lodev09)
2018 - Modified by Kevin Roth / [@rothkj1022](https://twitter.com/rothkj1022)

## License

Released under the [MIT License](http://opensource.org/licenses/MIT).
See [LICENSE](LICENSE) file.
Loading