Files
Gnuboard5/lib/Cache/obj.class.php
T
whitedot e4bd69ab82 fix: 객체 캐시의 타입별 저장소 분리로 값 충돌 방지
기존 public 멤버를 유지하면서 기타 타입의 저장소에 타입 차원을 추가하고 캐시 접근 경로를 공통화한다. API와 clone 동작을 유지하고 직접 멤버 접근 코드의 이전 방법을 문서화한다.

검증: PHP 5.2.17 및 PHP 8.4.22에서 구문 검사와 객체 캐시 회귀 테스트 통과.
2026-09-09 07:58:16 +00:00

69 lines
2.1 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
Class G5_object_cache {
/** @deprecated 직접 접근 대신 get/set/exists/delete 메서드를 사용한다. */
public $writes = array();
/** @deprecated 직접 접근 대신 get/set/exists/delete 메서드를 사용한다. */
public $contents = array();
/** @deprecated 타입별 $etcs[$type][$group][$key] 구조. 메서드 사용 권장. */
public $etcs = array();
// 각 타입의 유일한 저장소를 참조로 반환한다. 빈 타입 버킷은 요청 종료까지 유지한다.
private function &get_type_cache($type) {
if ($type === 'bbs') {
return $this->writes;
}
if ($type === 'content') {
return $this->contents;
}
if (!isset($this->etcs[$type])) {
$this->etcs[$type] = array();
}
return $this->etcs[$type];
}
function get($type, $key, $group = 'default') {
if (!$this->exists($type, $key, $group)) {
return false;
}
$datas = &$this->get_type_cache($type);
if (is_object($datas[$group][$key])) {
return clone $datas[$group][$key];
}
return $datas[$group][$key];
}
function exists($type, $key, $group = 'default') {
$datas = &$this->get_type_cache($type);
return isset($datas[$group]) && (isset($datas[$group][$key]) || array_key_exists($key, $datas[$group]));
}
function set($type, $key, $data = array(), $group = 'default') {
if (is_object($data)) {
$data = clone $data;
}
$datas = &$this->get_type_cache($type);
$datas[$group][$key] = $data;
}
/**
* 지정한 타입, 그룹, 키의 캐시 데이터만 제거한다.
* @param string $type
* @param string $key
* @param string $group
* @return bool
*/
function delete($type, $key, $group = 'default') {
if (!$this->exists($type, $key, $group)) {
return false;
}
$datas = &$this->get_type_cache($type);
unset($datas[$group][$key]);
return true;
}
}