Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
6f4c3c20
Commit
6f4c3c20
authored
Feb 08, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
880422ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
52 deletions
+73
-52
Cache.php
lib/Doctrine/Cache.php
+52
-49
Array.php
lib/Doctrine/Cache/Array.php
+21
-3
No files found.
lib/Doctrine/Cache.php
View file @
6f4c3c20
...
...
@@ -35,12 +35,12 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
/**
* @var array $_options an array of general caching options
*/
protected
$_options
=
array
(
'size'
=>
1000
,
'lifeTime'
=>
3600
,
'
statsPropability'
=>
0.7
5
,
'savePropability'
=>
0.10
,
'cleanPropability'
=>
0.01
,
'statsFile'
=>
'../data/stats.cache'
,
protected
$_options
=
array
(
'size'
=>
1000
,
'lifeTime'
=>
3600
,
'
addStatsPropability'
=>
0.2
5
,
'savePropability'
=>
0.10
,
'cleanPropability'
=>
0.01
,
'statsFile'
=>
'../data/stats.cache'
,
);
/**
* @var array $_queries query stack
...
...
@@ -211,50 +211,63 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
*
* @return boolean
*/
public
function
processAll
()
public
function
clean
()
{
$content
=
file_get_contents
(
$this
->
_statsFile
);
$queries
=
explode
(
"
\n
"
,
$content
);
$rand
=
(
mt_rand
()
/
mt_getrandmax
());
$stats
=
array
();
if
(
$rand
<=
$this
->
_options
[
'cleanPropability'
])
{
$content
=
file_get_contents
(
$this
->
_statsFile
);
$queries
=
explode
(
"
\n
"
,
$content
);
foreach
(
$queries
as
$query
)
{
if
(
is_array
(
$query
))
{
$query
=
$query
[
0
];
$stats
=
array
();
foreach
(
$queries
as
$query
)
{
if
(
is_array
(
$query
))
{
$query
=
$query
[
0
];
}
if
(
isset
(
$stats
[
$query
]))
{
$stats
[
$query
]
++
;
}
else
{
$stats
[
$query
]
=
1
;
}
}
if
(
isset
(
$stats
[
$query
]))
{
$stats
[
$query
]
++
;
}
else
{
$stats
[
$query
]
=
1
;
sort
(
$stats
);
$i
=
$this
->
_options
[
'size'
];
while
(
$i
--
)
{
$element
=
next
(
$stats
);
$query
=
key
(
$stats
);
if
(
is_array
(
$query
))
{
$hash
=
md5
(
serialize
(
$query
));
}
else
{
$hash
=
md5
(
$query
);
}
$this
->
_driver
->
delete
(
$hash
);
}
}
sort
(
$stats
);
$i
=
$this
->
_options
[
'size'
];
while
(
$i
--
)
{
$element
=
next
(
$stats
);
$query
=
key
(
$stats
);
$conn
=
Doctrine_Manager
::
getConnection
(
$element
[
1
]);
$data
=
$conn
->
fetchAll
(
$query
);
$this
->
_driver
->
save
(
serialize
(
$data
),
$query
,
$this
->
_options
[
'lifetime'
]);
}
}
/**
*
flush
*
appendStats
*
* adds all queries to stats file
* @return void
*/
public
function
flush
()
public
function
appendStats
()
{
if
(
$this
->
_options
[
'statsFile'
]
!==
false
)
{
if
(
!
file_exists
(
$this
->
_options
[
'statsFile'
]))
{
throw
new
Doctrine_Cache_Exception
(
"Couldn't save cache statistics. Cache statistics file doesn't exists!"
);
}
$rand
=
(
mt_rand
()
/
mt_getrandmax
());
file_put_contents
(
$this
->
_options
[
'statsFile'
],
implode
(
"
\n
"
,
$this
->
_queries
));
if
(
$rand
<=
$this
->
_options
[
'addStatsPropability'
])
{
file_put_contents
(
$this
->
_options
[
'statsFile'
],
implode
(
"
\n
"
,
$this
->
_queries
));
}
}
}
/**
...
...
@@ -281,10 +294,10 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this
->
success
=
(
$data
)
?
true
:
false
;
if
(
!
$data
)
{
$rand
=
(
rand
(
1
,
10000
)
/
(
10000
*
100
));
$rand
=
(
mt_rand
()
/
mt_getrandmax
(
));
if
(
$rand
<
$this
->
_options
[
'savePropability'
])
{
$stmt
=
$event
->
getInvoker
()
->
query
(
$query
);
$stmt
=
$event
->
getInvoker
()
->
getAdapter
()
->
query
(
$query
);
$data
=
$stmt
->
fetchAll
(
Doctrine
::
FETCH_ASSOC
);
...
...
@@ -349,10 +362,13 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
$this
->
success
=
(
$data
)
?
true
:
false
;
if
(
!
$data
)
{
$rand
=
(
rand
(
1
,
10000
)
/
(
10000
*
100
));
$rand
=
(
mt_rand
()
/
mt_getrandmax
(
));
if
(
$rand
<
$this
->
_options
[
'savePropability'
])
{
$stmt
=
$event
->
getInvoker
()
->
execute
(
$event
->
getParams
());
if
(
$rand
<=
$this
->
_options
[
'savePropability'
])
{
$stmt
=
$event
->
getInvoker
()
->
getStatement
();
$stmt
->
execute
(
$event
->
getParams
());
$data
=
$stmt
->
fetchAll
(
Doctrine
::
FETCH_ASSOC
);
...
...
@@ -367,17 +383,4 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
}
return
(
bool
)
$data
;
}
/**
* processStats
*
* @return void
*/
public
function
processStats
()
{
$rand
=
(
rand
(
1
,
10000
)
/
(
10000
*
100
));
if
(
$rand
>
$this
->
_options
[
'statSlamDefense'
])
{
$this
->
flush
();
}
}
}
lib/Doctrine/Cache/Array.php
View file @
6f4c3c20
...
...
@@ -31,7 +31,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Cache_Array
class
Doctrine_Cache_Array
implements
Countable
{
/**
* @var array $data an array of cached data
...
...
@@ -74,7 +74,7 @@ class Doctrine_Cache_Array
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
* @return boolean true if no problem
*/
public
function
save
(
$id
,
$data
,
$lifeTime
=
false
)
public
function
save
(
$id
,
$data
,
$lifeTime
=
false
)
{
$this
->
data
[
$id
]
=
$data
;
}
...
...
@@ -86,6 +86,24 @@ class Doctrine_Cache_Array
*/
public
function
delete
(
$id
)
{
unset
(
$this
->
data
[
$id
]);
unset
(
$this
->
data
[
$id
]);
}
/**
* Remove all cache record
*
* @return boolean true if no problem
*/
public
function
deleteAll
()
{
$this
->
data
=
array
();
}
/**
* count
*
* @return integer
*/
public
function
count
()
{
return
count
(
$this
->
data
);
}
}
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