wiki.techinc.nl/includes/libs/objectcache/serialized/SerializedValueContainer.php
Derick Alangi 223aeae06d objectcache: Hard deprecate SerializedValueContainer::newUnified()
Introduced in I0667a02612526d8ddfd91d5de48b6faa78bd1ab5 (in 2019)
and used for consistency by default in BagOStuff::set(), even for the
99% of values that don't need segmentation.

The method was removed from use in I830c78a50efd1ba83fbe2aa39c1, due
to the overhead of SerializedValueContainer being undesirable, so there
is no longer a use case for it. If a value doesn't need segmentation,
it shouldn't be wrapped in SerializedValueContainer.

See https://codesearch.wmcloud.org/search/?q=SerializedValueContainer%3A%3AnewUnified&files=&excludeFiles=&repos=

Bug: T344521
Change-Id: Id1c283201cd42c4eabac8ef4d949329959016b18
2023-08-18 21:29:12 +00:00

63 lines
1.4 KiB
PHP

<?php
/**
* Helper class for segmenting large cache values without relying on serializing classes
*
* @since 1.34
*/
class SerializedValueContainer {
private const SCHEMA = '__svc_schema__';
// 64 bit UID
private const SCHEMA_UNIFIED = 'DAAIDgoKAQw';
// 64 bit UID
private const SCHEMA_SEGMENTED = 'CAYCDAgCDw4';
public const UNIFIED_DATA = '__data__';
public const SEGMENTED_HASHES = '__hashes__';
/**
* @deprecated since 1.41
* @param string $serialized
* @return stdClass
*/
public static function newUnified( $serialized ) {
wfDeprecated( __METHOD__, '1.41' );
return (object)[
self::SCHEMA => self::SCHEMA_UNIFIED,
self::UNIFIED_DATA => $serialized
];
}
/**
* @param string[] $segmentHashList Ordered list of hashes for each segment
* @return stdClass
*/
public static function newSegmented( array $segmentHashList ) {
return (object)[
self::SCHEMA => self::SCHEMA_SEGMENTED,
self::SEGMENTED_HASHES => $segmentHashList
];
}
/**
* @param mixed $value
* @return bool
*/
public static function isUnified( $value ) {
return (
$value instanceof stdClass &&
( $value->{self::SCHEMA} ?? null ) === self::SCHEMA_UNIFIED
);
}
/**
* @param mixed $value
* @return bool
*/
public static function isSegmented( $value ) {
return (
$value instanceof stdClass &&
( $value->{self::SCHEMA} ?? null ) === self::SCHEMA_SEGMENTED
);
}
}