Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
8dba47d4
Commit
8dba47d4
authored
13 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Add layer to select fast or slow cache for storing values
parent
a90089c7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cache.php
+10
-0
10 additions, 0 deletions
lib/cache.php
lib/cache/broker.php
+55
-0
55 additions, 0 deletions
lib/cache/broker.php
with
65 additions
and
0 deletions
lib/cache.php
+
10
−
0
View file @
8dba47d4
...
...
@@ -10,7 +10,17 @@ class OC_Cache {
static
protected
$cache
;
static
protected
function
init
()
{
$fast_cache
=
null
;
if
(
!
$fast_cache
&&
function_exists
(
'xcache_set'
))
{
$fast_cache
=
new
OC_Cache_XCache
();
}
if
(
!
$fast_cache
&&
function_exists
(
'apc_store'
))
{
$fast_cache
=
new
OC_Cache_APC
();
}
self
::
$cache
=
new
OC_Cache_File
();
if
(
$fast_cache
)
{
self
::
$cache
=
new
OC_Cache_Broker
(
$fast_cache
,
self
::
$cache
);
}
}
static
public
function
get
(
$key
)
{
...
...
This diff is collapsed.
Click to expand it.
lib/cache/broker.php
0 → 100644
+
55
−
0
View file @
8dba47d4
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class
OC_Cache_Broker
{
protected
$fast_cache
;
protected
$slow_cache
;
public
function
__construct
(
$fast_cache
,
$slow_cache
)
{
$this
->
fast_cache
=
$fast_cache
;
$this
->
slow_cache
=
$slow_cache
;
}
public
function
get
(
$key
)
{
if
(
$r
=
$this
->
fast_cache
->
get
(
$key
))
{
return
$r
;
}
return
$this
->
slow_cache
->
get
(
$key
);
}
public
function
set
(
$key
,
$value
,
$ttl
=
0
)
{
$set_slow
=
strlen
(
$value
)
>
8192
;
if
(
$set_slow
)
{
if
(
$this
->
fast_cache
->
hasKey
(
$key
))
{
$this
->
fast_cache
->
remove
(
$key
);
}
$this
->
slow_cache
->
set
(
$key
,
$value
,
$ttl
);
}
else
{
$this
->
fast_cache
->
set
(
$key
,
$value
,
$ttl
);
}
}
public
function
hasKey
(
$key
)
{
if
(
$this
->
fast_cache
->
hasKey
(
$key
))
{
return
true
;
}
return
$this
->
slow_cache
->
hasKey
(
$key
);
}
public
function
remove
(
$key
)
{
if
(
$this
->
fast_cache
->
remove
(
$key
))
{
return
true
;
}
return
$this
->
slow_cache
->
remove
(
$key
);
}
public
function
clear
(){
$this
->
fast_cache
->
clear
();
$this
->
slow_cache
->
clear
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment