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
Show 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
...
...
@@ -37,7 +37,7 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
*/
protected
$_options
=
array
(
'size'
=>
1000
,
'lifeTime'
=>
3600
,
'
statsPropability'
=>
0.7
5
,
'
addStatsPropability'
=>
0.2
5
,
'savePropability'
=>
0.10
,
'cleanPropability'
=>
0.01
,
'statsFile'
=>
'../data/stats.cache'
,
...
...
@@ -211,8 +211,11 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
*
* @return boolean
*/
public
function
processAll
()
public
function
clean
()
{
$rand
=
(
mt_rand
()
/
mt_getrandmax
());
if
(
$rand
<=
$this
->
_options
[
'cleanPropability'
])
{
$content
=
file_get_contents
(
$this
->
_statsFile
);
$queries
=
explode
(
"
\n
"
,
$content
);
...
...
@@ -235,18 +238,24 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
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'
]);
if
(
is_array
(
$query
))
{
$hash
=
md5
(
serialize
(
$query
));
}
else
{
$hash
=
md5
(
$query
);
}
$this
->
_driver
->
delete
(
$hash
);
}
}
}
/**
*
flush
*
appendStats
*
* adds all queries to stats file
* @return void
*/
public
function
flush
()
public
function
appendStats
()
{
if
(
$this
->
_options
[
'statsFile'
]
!==
false
)
{
...
...
@@ -254,9 +263,13 @@ class Doctrine_Cache extends Doctrine_Db_EventListener implements Countable, Ite
throw
new
Doctrine_Cache_Exception
(
"Couldn't save cache statistics. Cache statistics file doesn't exists!"
);
}
$rand
=
(
mt_rand
()
/
mt_getrandmax
());
if
(
$rand
<=
$this
->
_options
[
'addStatsPropability'
])
{
file_put_contents
(
$this
->
_options
[
'statsFile'
],
implode
(
"
\n
"
,
$this
->
_queries
));
}
}
}
/**
* onPreQuery
* listens the onPreQuery event of Doctrine_Db
...
...
@@ -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
...
...
@@ -88,4 +88,22 @@ class Doctrine_Cache_Array
{
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