Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
outils
question2answer
Commits
f4c18bae
Commit
f4c18bae
authored
Jul 21, 2017
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add interface for cache drivers
parent
7db0cba8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
6 deletions
+99
-6
CacheDriver.php
qa-include/Q2A/Storage/CacheDriver.php
+84
-0
FileCacheDriver.php
qa-include/Q2A/Storage/FileCacheDriver.php
+15
-6
No files found.
qa-include/Q2A/Storage/CacheDriver.php
0 → 100644
View file @
f4c18bae
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Storage/FileCache.php
Description: Interface for drivers of caching system.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
/**
* Interface for caching drivers.
*/
interface
Q2A_Storage_CacheDriver
{
/**
* Get the cached data for the supplied key. Data can be any format but is usually an array.
* @param string $key The unique cache identifier.
*
* @return mixed The cached data, or null otherwise.
*/
public
function
get
(
$key
);
/**
* Store something in the cache along with the key and expiry time. Data gets 'serialized' to a string before storing.
* @param string $key The unique cache identifier.
* @param mixed $data The data to cache (in core Q2A this is usually an array).
* @param int $ttl Number of minutes for which to cache the data.
*
* @return bool Whether the file was successfully cached.
*/
public
function
set
(
$key
,
$data
,
$ttl
);
/**
* Delete an item from the cache.
* @param string $key The unique cache identifier.
*
* @return bool Whether the operation succeeded.
*/
public
function
delete
(
$key
);
/**
* Delete multiple items from the cache.
* @param int $limit Maximum number of items to process. 0 = unlimited
* @param int $start Offset from which to start (used for 'batching' deletes).
* @param bool $expiredOnly Delete cache only if it has expired.
*
* @return int Number of files deleted.
*/
public
function
clear
(
$limit
=
0
,
$start
=
0
,
$expiredOnly
=
false
);
/**
* Whether caching is available.
*
* @return bool
*/
public
function
isEnabled
();
/**
* Get the last error.
*
* @return string
*/
public
function
getError
();
/**
* Get current statistics for the cache.
*
* @return array Array of stats: 'files' => number of files, 'size' => total file size in bytes.
*/
public
function
getStats
();
}
qa-include/Q2A/Storage/FileCacheDriver.php
View file @
f4c18bae
...
...
@@ -23,7 +23,7 @@
/**
* Caches data (typically from database queries) to the filesystem.
*/
class
Q2A_Storage_FileCacheDriver
class
Q2A_Storage_FileCacheDriver
implements
Q2A_Storage_CacheDriver
{
private
$enabled
=
false
;
private
$error
;
...
...
@@ -58,6 +58,7 @@ class Q2A_Storage_FileCacheDriver
/**
* Get the cached data for the supplied key.
* @param string $key The unique cache identifier.
*
* @return string The cached data, or null otherwise.
*/
public
function
get
(
$key
)
...
...
@@ -95,6 +96,7 @@ class Q2A_Storage_FileCacheDriver
* @param string $key The unique cache identifier.
* @param mixed $data The data to cache (in core Q2A this is usually an array).
* @param int $ttl Number of minutes for which to cache the data.
*
* @return bool Whether the file was successfully cached.
*/
public
function
set
(
$key
,
$data
,
$ttl
)
...
...
@@ -119,7 +121,8 @@ class Q2A_Storage_FileCacheDriver
/**
* Delete an item from the cache.
* @param string $key The unique cache identifier.
* @param string $key The unique cache identifier.
*
* @return bool Whether the operation succeeded.
*/
public
function
delete
(
$key
)
...
...
@@ -136,9 +139,10 @@ class Q2A_Storage_FileCacheDriver
/**
* Delete multiple items from the cache.
* @param int $limit Maximum number of items to process. 0 = unlimited
* @param int $start Offset from which to start (used for 'batching' deletes).
* @param bool $expiredOnly Delete cache only if it has expired.
* @param int $limit Maximum number of items to process. 0 = unlimited
* @param int $start Offset from which to start (used for 'batching' deletes).
* @param bool $expiredOnly Delete cache only if it has expired.
*
* @return int Number of files deleted.
*/
public
function
clear
(
$limit
=
0
,
$start
=
0
,
$expiredOnly
=
false
)
...
...
@@ -186,6 +190,7 @@ class Q2A_Storage_FileCacheDriver
/**
* Whether caching is available.
*
* @return bool
*/
public
function
isEnabled
()
...
...
@@ -195,6 +200,7 @@ class Q2A_Storage_FileCacheDriver
/**
* Get the last error.
*
* @return string
*/
public
function
getError
()
...
...
@@ -204,6 +210,7 @@ class Q2A_Storage_FileCacheDriver
/**
* Get current statistics for the cache.
*
* @return array Array of stats: 'files' => number of files, 'size' => total file size in bytes.
*/
public
function
getStats
()
...
...
@@ -233,7 +240,8 @@ class Q2A_Storage_FileCacheDriver
/**
* Delete a specific file
* @param string $file Filename to delete
* @param string $file Filename to delete.
*
* @return bool Whether the file was deleted successfully.
*/
private
function
deleteFile
(
$file
)
...
...
@@ -248,6 +256,7 @@ class Q2A_Storage_FileCacheDriver
/**
* Generates filename for cache key, of the form `1/23/123abc`
* @param string $key The unique cache key.
*
* @return string
*/
private
function
getFilename
(
$key
)
...
...
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