Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shawn Barratt
SimpleCache
Commits
7abb515a
Commit
7abb515a
authored
Oct 15, 2015
by
Shawn Barratt
Browse files
init
parent
cd15b665
Changes
3
Hide whitespace changes
Inline
Side-by-side
composer.json
0 → 100755
View file @
7abb515a
{
"name"
:
"ethereal/simpleCache"
,
"type"
:
"project"
,
"require"
:
{
"php"
:
">=5.3.9"
,
},
"require-dev"
:
{
"php"
:
">=5.3.9"
,
"phpunit/phpunit"
:
"~4.8"
,
},
"minimum-stability"
:
"dev"
,
"autoload"
:
{
"psr-4"
:
{
"Ethereal\\"
:
"lib"
}
}
}
lib/Cache.php
0 → 100644
View file @
7abb515a
<?php
namespace
Ethereal
;
use
Predis\Client
;
class
Cache
extends
Predis\Client
{
protected
$namespace
=
''
;
public
function
set
(
$key
,
$val
,
$exp
=
null
)
{
if
(
!
is_string
(
$key
))
{
throw
new
\
Exception
(
"Key must be a string"
);
}
$key
=
"
{
$this
->
namespace
}{
$key
}
"
;
if
(
!
is_string
(
$val
))
{
$val
=
json_encode
(
$val
);
}
if
(
$exp
&&
is_numeric
(
$exp
))
{
return
parent
::
set
(
$key
,
$val
,
"EX
{
$exp
}
"
);
}
return
parent
::
set
(
$key
,
$val
);
}
public
function
get
(
$key
)
{
if
(
!
is_string
(
$key
))
{
throw
new
\
Exception
(
"Key must be a string"
);
}
$key
=
"
{
$this
->
namespace
}{
$key
}
"
;
$value
=
parent
::
get
(
$key
);
if
(
is_null
(
$value
))
{
return
null
;
}
if
(
$decode
=
json_decode
(
$value
))
{
return
$decode
;
}
return
$value
;
}
public
function
setNamespace
(
$namespace
)
{
$this
->
namespace
=
"
{
$namespace
}
"
;
}
}
tests/.gitkeep
0 → 100644
View file @
7abb515a
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment