feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.
Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
- Provider key: s3compatible
- Reads user-configured endpoint URL from settings
- Uses path-style URL access (required by most S3-compatible services)
- Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
- Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
This commit is contained in:
73
vendor/Aws3/Aws/LruArrayCache.php
vendored
Normal file
73
vendor/Aws3/Aws/LruArrayCache.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws;
|
||||
|
||||
/**
|
||||
* Simple in-memory LRU cache that limits the number of cached entries.
|
||||
*
|
||||
* The LRU cache is implemented using PHP's ordered associative array. When
|
||||
* accessing an element, the element is removed from the hash and re-added to
|
||||
* ensure that recently used items are always at the end of the list while
|
||||
* least recently used are at the beginning. When a value is added to the
|
||||
* cache, if the number of cached items exceeds the allowed number, the first
|
||||
* N number of items are removed from the array.
|
||||
*/
|
||||
class LruArrayCache implements CacheInterface, \Countable
|
||||
{
|
||||
/** @var int */
|
||||
private $maxItems;
|
||||
/** @var array */
|
||||
private $items = array();
|
||||
/**
|
||||
* @param int $maxItems Maximum number of allowed cache items.
|
||||
*/
|
||||
public function __construct($maxItems = 1000)
|
||||
{
|
||||
$this->maxItems = $maxItems;
|
||||
}
|
||||
public function get($key)
|
||||
{
|
||||
if (!isset($this->items[$key])) {
|
||||
return null;
|
||||
}
|
||||
$entry = $this->items[$key];
|
||||
// Ensure the item is not expired.
|
||||
if (!$entry[1] || \time() < $entry[1]) {
|
||||
// LRU: remove the item and push it to the end of the array.
|
||||
unset($this->items[$key]);
|
||||
$this->items[$key] = $entry;
|
||||
return $entry[0];
|
||||
}
|
||||
unset($this->items[$key]);
|
||||
return null;
|
||||
}
|
||||
public function set($key, $value, $ttl = 0)
|
||||
{
|
||||
// Only call time() if the TTL is not 0/false/null
|
||||
$ttl = $ttl ? \time() + $ttl : 0;
|
||||
$this->items[$key] = [$value, $ttl];
|
||||
// Determine if there are more items in the cache than allowed.
|
||||
$diff = \count($this->items) - $this->maxItems;
|
||||
// Clear out least recently used items.
|
||||
if ($diff > 0) {
|
||||
// Reset to the beginning of the array and begin unsetting.
|
||||
\reset($this->items);
|
||||
for ($i = 0; $i < $diff; $i++) {
|
||||
unset($this->items[\key($this->items)]);
|
||||
\next($this->items);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function remove($key)
|
||||
{
|
||||
unset($this->items[$key]);
|
||||
}
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return \count($this->items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user