nulib/php/src/db/cache/cache.php

38 lines
1.0 KiB
PHP

<?php
namespace nulib\db\cache;
use nulib\db\Capacitor;
use nulib\db\CapacitorStorage;
use nulib\db\sqlite\SqliteStorage;
class cache {
protected static ?CapacitorStorage $storage = null;
static function set_storage(CapacitorStorage $storage): CapacitorStorage {
return self::$storage = $storage;
}
protected static function get_storage(): CapacitorStorage {
return self::$storage ??= new SqliteStorage("");
}
protected static ?CacheChannel $channel = null;
static function set(?CacheChannel $channel): CacheChannel {
$channel ??= new CacheChannel();
new Capacitor(self::get_storage(), $channel);
return self::$channel = $channel;
}
static function get(): CacheChannel {
if (self::$channel !== null) return self::$channel;
else return self::set(null);
}
static function new(?RowsChannel $channel, $id=null, ?callable $builder=null): RowsChannel {
$channel ??= new RowsChannel($id, $builder);
new Capacitor(self::get_storage(), $channel);
return $channel;
}
}