init without trunk

This commit is contained in:
Kevin Adametz 2020-07-09 12:49:32 +02:00
parent ed24ac4994
commit bb809e7233
14652 changed files with 177862 additions and 94817 deletions

View file

@ -0,0 +1 @@
cache/

View file

@ -0,0 +1,14 @@
<?php
include('../autoload.php'); // If using composer
use Gregwar\Cache\GarbageCollect;
if (!is_dir('cache')) {
`mkdir cache`;
}
`touch -t 9901010101 cache/foo`;
`touch cache/bar`;
GarbageCollect::dropOldFiles(__DIR__.'/cache', 30, true);

View file

@ -0,0 +1,23 @@
<?php
include('../autoload.php');
$cache = new Gregwar\Cache\Cache;
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "First call: generating file...\n";
return strtoupper(file_get_contents('original.txt'));
});
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "Second call: generating file, this should not happen!...\n";
return strtoupper(file_get_contents('original.txt'));
});
echo "Waiting 4s...\n";
sleep(4);
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function() {
echo "Third call: generating cache file, because it expired...\n";
return strtoupper(file_get_contents('original.txt'));
});

View file

@ -0,0 +1,4 @@
There he goes.
One of God's own prototypes.
A high-powered mutant of some kind never even considered for mass production.
Too weird to live, and too rare to die.

View file

@ -0,0 +1,20 @@
<?php
include('../autoload.php'); // If using composer
use Gregwar\Cache\Cache;
$cache = new Cache;
$cache->setCacheDirectory('cache'); // This is the default
// If the cache exists, this will return it, else, the closure will be called
// to create this image
$file = $cache->getOrCreateFile('red-square.png', array(), function($filename) {
$i = imagecreatetruecolor(100, 100);
imagefill($i, 0, 0, 0xff0000);
file_put_contents($filename, 'abc');
imagepng($i, 'a.png');
imagepng($i, $filename);
});
echo $file, "\n";

View file

@ -0,0 +1,20 @@
<?php
include('../autoload.php'); // If using composer
use Gregwar\Cache\Cache;
$cache = new Cache;
$cache->setCacheDirectory('cache'); // This is the default
// If the cache exists, this will return it, else, the closure will be called
// to create this image
$data = $cache->getOrCreate('red-square.png', array(), function($filename) {
$i = imagecreatetruecolor(100, 100);
imagefill($i, 0, 0, 0xff0000);
file_put_contents($filename, 'abc');
imagepng($i, $filename);
});
header('Content-type: image/png');
echo $data;

View file

@ -0,0 +1,14 @@
<?php
include('../autoload.php');
use Gregwar\Cache\Cache;
$cache = new Cache;
$data = $cache->getOrCreate('uppercase.txt', array('younger-than' => 'original.txt'), function() {
echo "Generating file...\n";
return strtoupper(file_get_contents('original.txt'));
});
echo $data;