Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jun 14, 2024
1 parent e21f4e0 commit ff0df9c
Show file tree
Hide file tree
Showing 4 changed files with 786 additions and 0 deletions.
84 changes: 84 additions & 0 deletions plugin/Cache/Objects/CacheDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

require_once $global['systemRootPath'] . 'plugin/Cache/Objects/CachesInDB.php';
require_once $global['systemRootPath'] . 'plugin/Cache/Objects/CachesInDBMem.php';

class CacheDB
{
public static $loggedType_NOT_LOGGED = 'n';
public static $loggedType_LOGGED = 'l';
public static $loggedType_ADMIN = 'a';
public static $prefix = 'ypt_cache_';
static $CACHE_ON_DISK = 'disk';
static $CACHE_ON_MEMORY = 'mem';
private static $cacheType = 'disk';

public static function encodeContent($content)
{
return CachesInDB::encodeContent($content);
}

public static function deleteCacheStartingWith($name, $schedule=true)
{
if($schedule){
//insert
return Cache_schedule_delete::insert($name);
}else{
try {
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::_deleteCacheStartingWith($name);
}else{
return CachesInDB::_deleteCacheStartingWith($name);
}
} catch (\Throwable $th) {
_error_log("CacheDB::deleteCacheStartingWith($name)");
}
}
}

public static function deleteCacheWith($name)
{
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::_deleteCacheWith($name);
}else{
return CachesInDB::_deleteCacheWith($name);
}
}

public static function deleteAllCache()
{
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::_deleteAllCache();
}else{
return CachesInDB::_deleteAllCache();
}
}

public static function deleteCache($name)
{
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::_deleteCache($name);
}else{
return CachesInDB::_deleteCache($name);
}
}

public static function getCache($name, $domain, $ishttps, $user_location, $loggedType, $ignoreMetadata = false)
{
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::_getCache($name, $domain, $ishttps, $user_location, $loggedType, $ignoreMetadata);
}else{
return CachesInDB::_getCache($name, $domain, $ishttps, $user_location, $loggedType, $ignoreMetadata);
}
}


public static function setBulkCache($cacheArray, $metadata)
{
if(self::$cacheType == self::$CACHE_ON_MEMORY){
return CachesInDBMem::setBulkCache($cacheArray, $metadata);
}else{
return CachesInDB::setBulkCache($cacheArray, $metadata);
}
}
}
45 changes: 45 additions & 0 deletions plugin/Cache/Objects/Cache_schedule_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

require_once dirname(__FILE__) . '/../../../videos/configuration.php';

class Cache_schedule_delete extends ObjectYPT {

protected $id,$name;

static function getSearchFieldsNames() {
return array('name');
}

static function getTableName() {
return 'cache_schedule_delete';
}

function setId($id) {
$this->id = intval($id);
}

function setName($name) {
$this->name = $name;
}


function getId() {
return intval($this->id);
}

function getName() {
return $this->name;
}

public static function insert($name) {
$sql = "INSERT IGNORE INTO cache_schedule_delete (name) VALUES (?)";
$res = sqlDAL::writeSql($sql, "s", [$name]);
if ($res) {
return true;
} else {
error_log("ObjectYPT::insert::Error on save: " . $sql . " Error : " . json_encode($res));
return false;
}
}

}
Loading

0 comments on commit ff0df9c

Please sign in to comment.