Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97555491
PhutilKeyValueCacheNamespace.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 5, 05:58
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Jan 7, 05:58 (2 d)
Engine
blob
Format
Raw Data
Handle
23425700
Attached To
rPHU libphutil
PhutilKeyValueCacheNamespace.php
View Options
<?php
final
class
PhutilKeyValueCacheNamespace
extends
PhutilKeyValueCacheProxy
{
private
$namespace
;
public
function
setNamespace
(
$namespace
)
{
if
(
strpos
(
$namespace
,
':'
)
!==
false
)
{
throw
new
Exception
(
pht
(
"Namespace can't contain colons."
));
}
$this
->
namespace
=
$namespace
.
':'
;
return
$this
;
}
public
function
setKeys
(
array
$keys
,
$ttl
=
null
)
{
return
parent
::
setKeys
(
array_combine
(
$this
->
prefixKeys
(
array_keys
(
$keys
)),
$keys
),
$ttl
);
}
public
function
getKeys
(
array
$keys
)
{
$results
=
parent
::
getKeys
(
$this
->
prefixKeys
(
$keys
));
if
(!
$results
)
{
return
array
();
}
return
array_combine
(
$this
->
unprefixKeys
(
array_keys
(
$results
)),
$results
);
}
public
function
deleteKeys
(
array
$keys
)
{
return
parent
::
deleteKeys
(
$this
->
prefixKeys
(
$keys
));
}
private
function
prefixKeys
(
array
$keys
)
{
if
(
$this
->
namespace
==
null
)
{
throw
new
Exception
(
pht
(
'Namespace not set.'
));
}
$prefixed_keys
=
array
();
foreach
(
$keys
as
$key
)
{
$prefixed_keys
[]
=
$this
->
namespace
.
$key
;
}
return
$prefixed_keys
;
}
private
function
unprefixKeys
(
array
$keys
)
{
if
(
$this
->
namespace
==
null
)
{
throw
new
Exception
(
pht
(
'Namespace not set.'
));
}
$unprefixed_keys
=
array
();
foreach
(
$keys
as
$key
)
{
$unprefixed_keys
[]
=
substr
(
$key
,
strlen
(
$this
->
namespace
));
}
return
$unprefixed_keys
;
}
}
Event Timeline
Log In to Comment