Skip to content

Commit

Permalink
Added necessary cache adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-remarkety committed Feb 16, 2022
1 parent 109650e commit 8e1c64b
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 197 deletions.
10 changes: 10 additions & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ignore eclipse files
.settings
.buildpath

# ignore third party libs
vendor

# ignore the composer lock file
composer.lock

23 changes: 23 additions & 0 deletions library/Bisna/Common/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Bisna\Common\Cache;

use Cache\Adapter\PHPArray\ArrayCachePool;

class ArrayCache extends ArrayCachePool
{
private string $_namespace;
public function __construct(array $options)
{
$limit = $options['limit'] ?? null;
parent::__construct($limit);
}

public function setNamespace($namespace) {
$this->_namespace = $namespace;
}

public function getNamespace() {
return $this->_namespace;
}
}
29 changes: 29 additions & 0 deletions library/Bisna/Common/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Bisna\Common\Cache;

use Cache\Adapter\Filesystem\FilesystemCachePool;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;

class FilesystemCache extends FilesystemCachePool
{
private string $_namespace;

public function __construct(array $options)
{
$filesystemRoot = $options['directory'];
$filesystemAdapter = new Local($filesystemRoot);
$filesystem = new Filesystem($filesystemAdapter);
parent::__construct($filesystem);
}

public function setNamespace($namespace) {
$this->_namespace = $namespace;
}

public function getNamespace() {
return $this->_namespace;
}
}
28 changes: 28 additions & 0 deletions library/Bisna/Common/Cache/MemcacheCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Bisna\Common\Cache;

use Cache\Adapter\Memcached\MemcachedCachePool;

class MemcacheCache extends MemcachedCachePool {

private string $_namespace;

public function __construct(array $options) {
$cache = new \Memcached();
foreach ($options['servers'] as $server) {
$host = $server['host'] ?? 'localhost';
$port = $server['port'] ?? 11211;
$cache->addServer($host, $port);
}
parent::__construct($cache);
}

public function setNamespace($namespace) {
$this->_namespace = $namespace;
}

public function getNamespace() {
return $this->_namespace;
}
}
Loading

0 comments on commit 8e1c64b

Please sign in to comment.