package.xml0000664000175000017500000006260713054773062011321 0ustar janjan Horde_Cache pear.horde.org Horde Caching API A simple, functional caching API, with the option to store the cached data on the filesystem, in one of the PHP opcode cache systems (APC, eAcclerator, XCache), Memcache, MongoDB, Redis, user session, an SQL table, or a combination of these. Chuck Hagenbuch chuck chuck@horde.org yes Michael Slusarz slusarz slusarz@horde.org yes 2017-02-27 2.5.5 2.5.0 stable stable LGPL-2.1 * [jan] Fix MongoDB backend with mongodb extension. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Compress_Fast pear.horde.org 1.0.0 2.0.0alpha1 2.0.0alpha1 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 hash Horde_Db pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 Horde_HashTable pear.horde.org 1.0.0 2.0.0alpha1 2.0.0alpha1 Horde_Log pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Memcache pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Mongo pear.horde.org 1.0.0 2.0.0alpha1 2.0.0alpha1 APC pecl.php.net 3.1.1 apc eaccelerator 0.9.5 0.9.6 0.9.6 xcache 0.0.1 0.0.1 alpha alpha 2004-01-01 LGPL-2.1 Initial packaging. 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 LGPL-2.1 * First alpha release for Horde 4. * Add SQL backend. * Converted to package.xml 2.0 for pear.horde.org. * Add APC, eAccelerator, and XCache backends (duck@obala.net). * Abstracted storage-specific code into 'Storage' drivers. * Add option to transparently compress cache data using lzf. * Added Horde_Cache_Session::. * Horde_Cache::set() no longer returns a boolean result. * Added Horde_Cache_Exception::. * Removed dependency on Horde Core. * Added Horde_Cache#clear() 1.0.0beta1 1.0.0 beta beta 2011-03-16 LGPL-2.1 * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 LGPL-2.1 * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 LGPL-2.1 * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 LGPL-2.1 * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-04-20 LGPL-2.1 * [jan] Relax required lzf extension version. 1.0.2 1.0.0 stable stable 2011-05-03 LGPL-2.1 * [jan] Fix expiring entries in sub-storages of Stack driver (Bug #9949). 1.0.3 1.0.0 stable stable 2011-05-03 LGPL-2.1 * [jan] Fix dependency. 1.0.4 1.0.0 stable stable 2011-06-01 LGPL-2.1 * [mms] Fix memcache duplicate keys (Bug #10072; goncalo.queiros@portugalmail.net). 1.0.5 1.0.0 stable stable 2012-04-10 LGPL-2.1 * [rla] Add license file. 1.0.6 1.0.0 stable stable LGPL-2.1 * [mms] Correctly invalidate cache when write error occurs while using the stack driver. 2.0.0alpha1 1.0.0 alpha stable 2012-07-05 LGPL-2.1 * First alpha release for Horde 5. 2.0.0beta1 1.0.0 beta stable 2012-07-19 LGPL-2.1 * First beta release for Horde 5. * [mms] Add Horde_Cache#testReadWrite(). 2.0.0RC1 1.0.0 beta stable 2012-10-26 LGPL-2.1 * [mms] Correctly invalidate cache when write error occurs while using the stack driver. 2.0.0 1.0.0 stable stable 2012-10-30 LGPL-2.1 * First stable release for Horde 5. 2.0.1 1.0.0 stable stable 2012-11-19 LGPL-2.1 * [jan] Re-packaged 2.0.0 release. 2.0.2 1.0.0 stable stable 2013-03-05 LGPL-2.1 * [mms] Abstract data compression out into Horde_Compress_Fast package. 2.0.3 1.0.0 stable stable 2013-03-05 LGPL-2.1 * [mms] Fix regression preventing compression of Horde_Cache data (Bug #12088). 2.0.4 1.0.0 stable stable 2013-04-08 LGPL-2.1 * [mms] Make Horde_Compress_Fast a required package (Bug #12166). * [mms] Fix serialization of all storage drivers. 2.1.0 1.1.0 stable stable 2013-05-02 LGPL-2.1 * [mms] Add MongoDB cache driver. 2.2.0 2.2.0 stable stable 2013-06-04 LGPL-2.1 * [mms] Fix return from get() when using the Hashtable driver. * [mms] Fix hashtable driver name. * [mms] Horde_Memcache cache driver is now deprecated in favor of the Horde_HashTable driver. * [mms] Add Horde_HashTable cache driver. 2.2.1 2.2.0 stable stable 2013-07-16 LGPL-2.1 * [mms] Fix explicit key expiration (João Machado <geral@jpaulo.eu>). 2.3.0 2.3.0 stable stable 2013-10-08 LGPL-2.1 * [mms] Fix key expiration for APC, Eaccelerator, and Xcache (Bug #12735). * [mms] Add Horde_Cache_Storage_Memoryoverlay driver. 2.4.0 2.4.0 stable stable 2014-01-24 LGPL-2.1 * [mms] Fix lifetime usage in the file driver. * [mms] Add 'no_gc' parameter to the Horde_Cache_Storage_File driver. 2.4.1 2.4.0 stable stable 2014-02-11 LGPL-2.1 * [mms] Cache prefix should be handled by Hashtable driver, not underlying backend object. 2.4.2 2.4.0 stable stable 2014-04-03 LGPL-2.1 * [mms] Hashtable driver now respects lifetime parameter in the get() and exists() methods (Bug #13085). 2.5.0 2.5.0 stable stable 2014-05-06 LGPL-2.1 * [mms] Add Memory driver. * [mms] Deprecate Memoryoverlay and Mock drivers. 2.5.1 2.5.0 stable stable 2016-01-05 LGPL-2.1 * [jan] Improve Oracle compatibility. 2.5.2 2.5.0 stable stable 2016-02-01 LGPL-2.1 * [jan] Improve performance and memory consumption of garbage collection in File driver. * [jan] Fix garbage collection in File driver. * [jan] Fix caching issues within the same request in the Memcache driver. * [jan] Fix the Mongo driver's expire() if not using a logger. * [jan] Add unit tests. 2.5.3 2.5.0 stable stable 2016-02-18 LGPL-2.1 * [jan] Fix incomplete migration from old to new garbage collection in file backend (Bug #14258). * [jan] Mark PHP 7 as supported. 2.5.4 2.5.0 stable stable 2016-08-31 LGPL-2.1 * [jan] Run Memcache and Mongo tests on PHP 7 too. 2.5.5 2.5.0 stable stable 2017-02-27 LGPL-2.1 * [jan] Fix MongoDB backend with mongodb extension. Horde_Cache-2.5.5/doc/Horde/Cache/COPYING0000664000175000017500000005764613054773062015650 0ustar janjan GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Horde_Cache-2.5.5/doc/horde.yml0000664000175000017500000000050313054773062014351 0ustar janjan--- id: Cache name: Cache full: Caching library description: > A simple, functional caching API, with the option to store the cached data on the filesystem, in one of the PHP opcode cache systems (APC, eAcclerator, XCache), Memcache, MongoDB, Redis, user session, an SQL table, or a combination of these. list: dev Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Apc.php0000664000175000017500000000514213054773062017416 0ustar janjan * @category Horde * @copyright 2006-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Apc extends Horde_Cache_Storage_Base { /** * Constructor. * * @param array $params Optional parameters: *
     *   - prefix: (string) The prefix to use for the cache keys.
     *             DEFAULT: ''
     * 
*/ public function __construct(array $params = array()) { parent::__construct(array_merge(array( 'prefix' => '', ), $params)); } /** */ public function get($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); return apc_fetch($key); } /** */ public function set($key, $data, $lifetime = 0) { $key = $this->_params['prefix'] . $key; if (apc_store($key . '_expire', time(), $lifetime)) { apc_store($key, $data, $lifetime); } } /** */ public function exists($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); return (apc_fetch($key) !== false); } /** */ public function expire($key) { $key = $this->_params['prefix'] . $key; apc_delete($key . '_expire'); return apc_delete($key); } /** */ public function clear() { if (!apc_clear_cache('user')) { throw new Horde_Cache_Exception('Clearing APC cache failed'); } } /** * Set expire time on each call since APC sets it on cache creation. * * @param string $key Cache key to expire. * @param integer $lifetime Lifetime of the data in seconds. */ protected function _setExpire($key, $lifetime) { if ($lifetime == 0) { // Don't expire. return; } $expire = apc_fetch($key . '_expire'); // Set prune period. if ($expire + $lifetime < time()) { // Expired apc_delete($key); apc_delete($key . '_expire'); } } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Base.php0000664000175000017500000000621413054773062017566 0ustar janjan * @category Horde * @copyright 2010-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ abstract class Horde_Cache_Storage_Base implements Serializable { /** * Logger. * * @var Horde_Log_Logger */ protected $_logger; /** * Parameters. * * @var array */ protected $_params = array(); /** * Constructor. * * @param array $params Configuration parameters. */ public function __construct(array $params = array()) { $this->_params = array_merge($this->_params, $params); $this->_initOb(); } /** * Do initialization tasks. */ protected function _initOb() { } /** * Set the logging object. * * @param Horde_Log_Logger $logger Log object. */ public function setLogger($logger) { $this->_logger = $logger; } /** * Retrieve cached data. * * @param string $key Object ID to query. * @param integer $lifetime Lifetime of the object in seconds. * * @return mixed Cached data, or false if none was found. */ abstract public function get($key, $lifetime = 0); /** * Store an object in the cache. * * @param string $key Object ID used as the caching key. * @param mixed $data Data to store in the cache. * @param integer $lifetime Object lifetime - i.e. the time before the * data becomes available for garbage * collection. If 0 will not be GC'd. */ abstract public function set($key, $data, $lifetime = 0); /** * Checks if a given key exists in the cache, valid for the given * lifetime. * * @param string $key Cache key to check. * @param integer $lifetime Lifetime of the key in seconds. * * @return boolean Existence. */ abstract public function exists($key, $lifetime = 0); /** * Expire any existing data for the given key. * * @param string $key Cache key to expire. * * @return boolean Success or failure. */ abstract public function expire($key); /** * Clears all data from the cache. * * @throws Horde_Cache_Exception */ abstract public function clear(); /* Serializable methods. */ /** */ public function serialize() { return serialize(array( $this->_params, $this->_logger )); } /** */ public function unserialize($data) { @list($this->_params, $this->_logger) = @unserialize($data); $this->_initOb(); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Eaccelerator.php0000664000175000017500000000550213054773062021304 0ustar janjan * @category Horde * @copyright 2006-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Eaccelerator extends Horde_Cache_Storage_Base { /** * Constructor. * * @param array $params Optional parameters: *
     *   - prefix: (string) The prefix to use for the cache keys.
     *             DEFAULT: ''
     * 
* * @throws Horde_Cache_Exception */ public function __construct(array $params = array()) { if (!function_exists('eaccelerator_gc')) { throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.'); } parent::__construct(array_merge(array( 'prefix' => '', ), $params)); } /** */ public function get($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); return eaccelerator_get($key); } /** */ public function set($key, $data, $lifetime = 0) { $key = $this->_params['prefix'] . $key; if (eaccelerator_put($key . '_expire', time(), $lifetime)) { eaccelerator_put($key, $data, $lifetime); } } /** */ public function exists($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); return eaccelerator_get($key) !== false; } /** */ public function expire($key) { $key = $this->_params['prefix'] . $key; eaccelerator_rm($key . '_expire'); return eaccelerator_rm($key); } /** */ public function clear() { eaccelerator_clear(); } /** * Set expire time on each call since eAccelerator sets it on * cache creation. * * @param string $key Cache key to expire. * @param integer $lifetime Lifetime of the data in seconds. */ protected function _setExpire($key, $lifetime) { if ($lifetime == 0) { // Don't expire. return; } $expire = eaccelerator_get($key . '_expire'); // Set prune period. if ($expire + $lifetime < time()) { // Expired eaccelerator_rm($key); eaccelerator_rm($key . '_expire'); } } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/File.php0000664000175000017500000002354213054773062017576 0ustar janjan * @author Chuck Hagenbuch * @author Michael Slusarz * @category Horde * @copyright 1999-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_File extends Horde_Cache_Storage_Base { /* Location of the garbage collection data file. */ const GC_FILE = 'horde_cache_gc'; /** * List of key to filename mappings. * * @var array */ protected $_file = array(); /** * Constructor. * * @param array $params Optional parameters: *
     *   - dir: (string) The base directory to store the cache files in.
     *          DEFAULT: System default
     *   - no_gc: (boolean) If true, don't perform garbage collection.
     *            DEFAULT: false
     *   - prefix: (string) The filename prefix to use for the cache files.
     *             DEFAULT: 'cache_'
     *   - sub: (integer) If non-zero, the number of subdirectories to create
     *          to store the file (i.e. PHP's session.save_path).
     *          DEFAULT: 0
     * 
*/ public function __construct(array $params = array()) { $params = array_merge(array( 'prefix' => 'cache_', 'sub' => 0 ), $params); if (!isset($params['dir']) || !@is_dir($params['dir'])) { $params['dir'] = sys_get_temp_dir(); } parent::__construct($params); } /** * Destructor. */ public function __destruct() { $c_time = time(); /* Only do garbage collection 0.1% of the time we create an object. */ if (!empty($this->_params['no_gc']) || (intval(substr($c_time, -3)) !== 0)) { return; } $this->_gc(); } /** */ public function get($key, $lifetime = 0) { if (!$this->exists($key, $lifetime)) { /* Nothing cached, return failure. */ return false; } $filename = $this->_keyToFile($key); $size = filesize($filename); return $size ? @file_get_contents($filename) : ''; } /** */ public function set($key, $data, $lifetime = 0) { $filename = $this->_keyToFile($key, true); $tmp_file = Horde_Util::getTempFile('HordeCache', true, $this->_params['dir']); if (isset($this->_params['umask'])) { chmod($tmp_file, 0666 & ~$this->_params['umask']); } if (file_put_contents($tmp_file, $data) === false) { throw new Horde_Cache_Exception('Cannot write to cache directory ' . $this->_params['dir']); } @rename($tmp_file, $filename); if ($lifetime && ($fp = @fopen(dirname($filename) . '/' . self::GC_FILE, 'a'))) { // This may result in duplicate entries in GC_FILE, but we // will take care of these whenever we do GC and this is quicker // than having to check every time we access the file. fwrite($fp, $filename . "\t" . (time() + $lifetime) . "\n"); fclose($fp); } } /** */ public function exists($key, $lifetime = 0) { $filename = $this->_keyToFile($key); /* Key exists in the cache */ if (file_exists($filename)) { /* 0 means no expire. * Also, If the file was been created after the supplied value, * the data is valid (fresh). */ if (($lifetime == 0) || (time() - $lifetime <= filemtime($filename))) { return true; } @unlink($filename); } return false; } /** */ public function expire($key) { return @unlink($this->_keyToFile($key)); } /** */ public function clear() { foreach ($this->_getCacheFiles() as $val) { @unlink($val); } foreach ($this->_getGCFiles() as $val) { @unlink($val); } } /** * Return a list of cache files. * * @param string $start The directory to start searching. * * @return array Pathnames to cache files. */ protected function _getCacheFiles($start = null) { $paths = array(); try { $it = empty($this->_params['sub']) ? new DirectoryIterator($this->_params['dir']) : new RecursiveIteratorIterator(new RecursiveDirectoryIterator($start ?: $this->_params['dir']), RecursiveIteratorIterator::CHILD_FIRST); } catch (UnexpectedValueException $e) { return $paths; } foreach ($it as $val) { if (!$val->isDir() && ($fname = $val->getFilename()) && (strpos($fname, $this->_params['prefix']) === 0)) { $paths[$fname] = $val->getPathname(); } } return $paths; } /** * Return a list of GC indexes. * * @return array Pathnames to GC indexes. */ protected function _getGCFiles() { $glob = $this->_params['dir']; if (!empty($this->_params['sub'])) { $glob .= '/' . implode('/', array_fill(0, $this->_params['sub'], '*')); } $glob .= '/' . self::GC_FILE; return glob($glob); } /** * Map a cache key to a unique filename. * * @param string $key Cache key. * @param string $create Create path if it doesn't exist? * * @return string Fully qualified filename. */ protected function _keyToFile($key, $create = false) { if ($create || !isset($this->_file[$key])) { $dir = $this->_params['dir'] . '/'; $md5 = hash('md5', $key); $sub = ''; if (!empty($this->_params['sub'])) { $max = min($this->_params['sub'], strlen($md5)); for ($i = 0; $i < $max; $i++) { $sub .= $md5[$i]; if ($create && !is_dir($dir . $sub)) { if (!mkdir($dir . $sub)) { $sub = ''; break; } } $sub .= '/'; } } $this->_file[$key] = $dir . $sub . $this->_params['prefix'] . $md5; } return $this->_file[$key]; } /** * Garbage collector. */ protected function _gc() { $c_time = time(); if (!empty($this->_params['sub']) && file_exists($this->_params['dir'] . '/' . self::GC_FILE)) { // If we cannot migrate, we cannot GC either, because we expect the // new format. try { $this->_migrateGc(); } catch (Horde_Cache_Exception $e) { return; } } foreach ($this->_getGCFiles() as $filename) { $excepts = array(); if (is_readable($filename)) { $fp = fopen($filename, 'r'); while (!feof($fp) && ($data = fgets($fp))) { $parts = explode("\t", trim($data), 2); $excepts[$parts[0]] = $parts[1]; } } foreach ($this->_getCacheFiles(dirname($filename)) as $pname) { if (!empty($excepts[$pname]) && ($c_time > $excepts[$pname])) { @unlink($pname); unset($excepts[$pname]); } } if ($fp = @fopen($filename, 'w')) { foreach ($excepts as $key => $val) { fwrite($fp, $key . "\t" . $val . "\n"); } fclose($fp); } } } /** * Migrates single GC indexes to per-directory indexes. */ protected function _migrateGc() { // Read the old GC index. $filename = $this->_params['dir'] . '/' . self::GC_FILE; if (!is_readable($filename)) { return; } $fhs = array(); $fp = fopen($filename, 'r'); if (!flock($fp, LOCK_EX)) { throw new Horde_Cache_Exception('Cannot acquire lock for old garbage collection index'); } // Loops through all cached files from the old index and write their GC // information to the new GC indexes. while (!feof($fp) && ($data = fgets($fp))) { list($path, $time) = explode("\t", trim($data), 2); $dir = dirname($path); if ($dir == $this->_params['dir']) { continue; } if (!isset($fhs[$dir])) { $fhs[$dir] = @fopen($dir . '/' . self::GC_FILE, 'a'); // Maybe too many open file handles? if (!$fhs[$dir] && count($fhs)) { unset($fhs[$dir]); foreach ($fhs as $fh) { fclose($fh); } $fhs = array(); $fhs[$dir] = @fopen($dir . '/' . self::GC_FILE, 'a'); } if (!$fhs[$dir]) { throw new Horde_Cache_Exception('Cannot migrate to new garbage collection index format'); } } fwrite($fhs[$dir], $path . "\t" . $time . "\n"); } // Clean up. foreach ($fhs as $fh) { fclose($fh); } fclose($fp); unlink($filename); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Hashtable.php0000664000175000017500000000560513054773062020612 0ustar janjan * @category Horde * @copyright 2013-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache * @since 2.2.0 */ class Horde_Cache_Storage_Hashtable extends Horde_Cache_Storage_Base { /** * HashTable object. * * @var Horde_HashTable */ protected $_hash; /** * @param array $params Additional parameters: *
     *   - hashtable: (Horde_HashTable) [REQUIRED] A Horde_HashTable object.
     *   - prefix: (string) The prefix to use for the cache keys.
     *             DEFAULT: ''
     * 
*/ public function __construct(array $params = array()) { if (!isset($params['hashtable'])) { throw new InvalidArgumentException('Missing hashtable parameter.'); } parent::__construct(array_merge(array( 'prefix' => '' ), $params)); } /** */ protected function _initOb() { $this->_hash = $this->_params['hashtable']; } /** */ public function get($key, $lifetime = 0) { $dkey = $this->_getKey($key); $query = array($dkey); if ($lifetime) { $query[] = $lkey = $this->_getKey($key, true); } $res = $this->_hash->get($query); if ($lifetime && (!$res[$lkey] || (($lifetime + $res[$lkey]) < time()))) { return false; } return $res[$dkey]; } /** */ public function set($key, $data, $lifetime = 0) { $opts = array_filter(array( 'expire' => $lifetime )); $this->_hash->set($this->_getKey($key), $data, $opts); $this->_hash->set($this->_getKey($key, true), time(), $opts); } /** */ public function exists($key, $lifetime = 0) { return ($this->get($key, $lifetime) !== false); } /** */ public function expire($key) { $this->_hash->delete(array( $this->_getKey($key), $this->_getKey($key, true) )); } /** */ public function clear() { $this->_hash->clear(); } /** * Return the hashtable key. * * @param string $key Object ID. * @param boolean $ts Return the timestamp key? * * @return string Hashtable key ID. */ protected function _getKey($key, $ts = false) { return $this->_params['prefix'] . $key . ($ts ? '_t' : ''); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Memcache.php0000664000175000017500000000712713054773062020422 0ustar janjan * @author Michael Slusarz * @category Horde * @copyright 2006-2016 Horde LLC * @deprecated Use HashTable driver instead. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Memcache extends Horde_Cache_Storage_Base { /** * Cache results of exists()/get() calls (since we will get the entire * object on an exists() call anyway). * * @var array */ protected $_objectcache = array(); /** * Memcache object. * * @var Horde_Memcache */ protected $_memcache; /** * Construct a new Horde_Cache_Memcache object. * * @param array $params Parameter array: *
     *   - memcache: (Horde_Memcache) [REQUIRED] A Horde_Memcache object.
     *   - prefix: (string) The prefix to use for the cache keys.
     *             DEFAULT: ''
     * 
*/ public function __construct(array $params = array()) { if (!isset($params['memcache'])) { if (isset($params['hashtable'])) { $params['memcache'] = $params['hashtable']; } else { throw new InvalidArgumentException('Missing memcache object'); } } parent::__construct(array_merge(array( 'prefix' => '', ), $params)); } /** */ protected function _initOb() { $this->_memcache = $this->_params['memcache']; } /** */ public function get($key, $lifetime = 0) { $original_key = $key; $key = $this->_params['prefix'] . $key; if (isset($this->_objectcache[$key])) { return $this->_objectcache[$key]; } $key_list = array($key); if (!empty($lifetime)) { $key_list[] = $key . '_e'; } $res = $this->_memcache->get($key_list); if ($res === false) { return $this->_objectcache[$key] = false; } // If we can't find the expire time, assume we have exceeded it. if (empty($lifetime) || (($res[$key . '_e'] !== false) && ($res[$key . '_e'] + $lifetime > time()))) { $this->_objectcache[$key] = $res[$key]; } else { $this->expire($original_key); return false; } return $res[$key]; } /** */ public function set($key, $data, $lifetime = 0) { $key = $this->_params['prefix'] . $key; if ($this->_memcache->set($key . '_e', time(), $lifetime) !== false) { $this->_memcache->set($key, $data, $lifetime); unset($this->_objectcache[$key]); } } /** */ public function exists($key, $lifetime = 0) { return ($this->get($key, $lifetime) !== false); } /** */ public function expire($key) { $key = $this->_params['prefix'] . $key; $this->_objectcache[$key] = false; $this->_memcache->delete($key . '_e'); return $this->_memcache->delete($key); } /** */ public function clear() { $this->_memcache->flush(); $this->_objectcache = array(); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Memory.php0000664000175000017500000000315413054773062020164 0ustar janjan * @author Michael Slusarz * @category Horde * @copyright 2010-2016 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Cache * @package Cache * @since 2.5.0 */ class Horde_Cache_Storage_Memory extends Horde_Cache_Storage_Base { /** * Storage for this cache. * * @var array */ private $_cache = array(); /** */ public function get($key, $lifetime = 0) { return isset($this->_cache[$key]) ? $this->_cache[$key] : false; } /** */ public function set($key, $data, $lifetime = 0) { $this->_cache[$key] = $data; } /** */ public function exists($key, $lifetime = 0) { return isset($this->_cache[$key]); } /** */ public function expire($key) { unset($this->_cache[$key]); } /** */ public function clear() { $this->_cache = array(); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Memoryoverlay.php0000664000175000017500000000462113054773062021566 0ustar janjan * @category Horde * @copyright 2013-2016 Horde LLC * @deprecated Use Memory driver as first backend in stack driver instead. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Cache * @package Cache */ class Horde_Cache_Storage_Memoryoverlay extends Horde_Cache_Storage_Base { /** * The memory cache. * * @var array */ private $_cache = array(); /** * Constructor. * * @param array $params Parameters: *
     *   - backend: (Horde_Cache_Storage_Base) [REQUIRED] The master storage
     *              backend.
     * 
*/ public function __construct(array $params = array()) { if (!isset($params['backend'])) { throw new InvalidArgumentException('Missing backend parameter.'); } parent::__construct($params); } /** */ public function get($key, $lifetime = 0) { if (!isset($this->_cache[$key])) { $this->_cache[$key] = $this->_params['backend']->get($key, $lifetime); } return $this->_cache[$key]; } /** */ public function set($key, $data, $lifetime = 0) { $this->_cache[$key] = $data; $this->_params['backend']->set($key, $data, $lifetime); } /** */ public function exists($key, $lifetime = 0) { return isset($this->_cache[$key]) ? true : $this->_params['backend']->exists($key, $lifetime); } /** */ public function expire($key) { unset($this->_cache[$key]); $this->_params['backend']->expire($key); } /** */ public function clear() { $this->_cache = array(); $this->_params['backend']->clear(); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Mock.php0000664000175000017500000000161313054773062017603 0ustar janjan * @category Horde * @copyright 2010-2017 Horde LLC * @deprecated Use Memory driver instead. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://pear.horde.org/index.php?package=Cache * @package Cache */ class Horde_Cache_Storage_Mock extends Horde_Cache_Storage_Memory { } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Mongo.php0000664000175000017500000001432713054773062017777 0ustar janjan * @category Horde * @copyright 2013-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Mongo extends Horde_Cache_Storage_Base { /* Field names. */ const CID = 'cid'; const DATA = 'data'; const EXPIRE = 'expire'; const TIMESTAMP = 'ts'; /** * The MongoDB Collection object for the cache data. * * @var MongoCollection */ protected $_db; /** * Constructor. * * @param array $params Parameters: *
     *   - collection: (string) The collection name.
     *   - mongo_db: [REQUIRED] (Horde_Mongo_Client) A MongoDB client object.
     * 
*/ public function __construct(array $params = array()) { if (!isset($params['mongo_db'])) { throw new InvalidArgumentException('Missing mongo_db parameter.'); } parent::__construct(array_merge(array( 'collection' => 'horde_cache' ), $params)); } /** * Destructor. */ public function __destruct() { /* Only do garbage collection 0.1% of the time we create an object. */ if (substr(time(), -3) === '000') { try { $this->_db->remove(array( self::EXPIRE => array( '$exists' => true, '$lt' => time() ) )); } catch (MongoException $e) { $this->_logger->log($e->getMessage(), 'DEBUG'); } } } /** */ protected function _initOb() { $this->_db = $this->_params['mongo_db']->selectCollection(null, $this->_params['collection']); } /** */ public function get($key, $lifetime = 0) { $okey = $key; $key = $this->_getCid($key); /* Build SQL query. */ $query = array( self::CID => $key ); // 0 lifetime checks for objects which have no expiration if ($lifetime != 0) { $query[self::TIMESTAMP] = array('$gte' => time() - $lifetime); } try { $result = $this->_db->findOne($query, array(self::DATA => true)); } catch (MongoException $e) { $this->_logger->log($e->getMessage(), 'DEBUG'); return false; } if (empty($result)) { /* No rows were found - cache miss */ if ($this->_logger) { $this->_logger->log(sprintf('Cache miss: %s (cache ID %s)', $okey, $key), 'DEBUG'); } return false; } if ($this->_logger) { $this->_logger->log(sprintf('Cache hit: %s (cache ID %s)', $okey, $key), 'DEBUG'); } return $result[self::DATA]->bin; } /** */ public function set($key, $data, $lifetime = 0) { $okey = $key; $key = $this->_getCid($key); $curr = time(); $data = array( self::CID => $key, self::DATA => new MongoBinData($data, MongoBinData::BYTE_ARRAY), self::TIMESTAMP => $curr ); // 0 lifetime indicates the object should not be GC'd. if (!empty($lifetime)) { $data[self::EXPIRE] = intval($lifetime) + $curr; } if ($this->_logger) { $this->_logger->log(sprintf( 'Cache set: %s (id %s set at %s%s)', $okey, $key, date('r', $curr), (isset($data[self::EXPIRE]) ? ' expires at ' . date('r', $data[self::EXPIRE]) : '') ), 'DEBUG'); } // Remove any old cache data and prevent duplicate keys try { $this->_db->update(array( self::CID => $key ), array( '$set' => $data ), array( 'upsert' => true, 'w' => 0 )); } catch (MongoException $e) { $this->_logger->log($e->getMessage(), 'DEBUG'); return false; } } /** */ public function exists($key, $lifetime = 0) { $okey = $key; $key = $this->_getCid($key); /* Build SQL query. */ $query = array( self::CID => $key ); // 0 lifetime checks for objects which have no expiration if ($lifetime != 0) { $query[self::TIMESTAMP] = array('$gte' => time() - $lifetime); } try { $result = $this->_db->findOne($query); } catch (MongoException $e) { $this->_logger->log($e->getMessage(), 'DEBUG'); return false; } if (is_null($result)) { if ($this->_logger) { $this->_logger->log(sprintf('Cache exists() miss: %s (cache ID %s)', $okey, $key), 'DEBUG'); } return false; } if ($this->_logger) { $this->_logger->log(sprintf('Cache exists() hit: %s (cache ID %s)', $okey, $key), 'DEBUG'); } return true; } /** */ public function expire($key) { $okey = $key; $key = $this->_getCid($key); try { $this->_db->remove(array( self::CID => $key )); if ($this->_logger) { $this->_logger->log(sprintf('Cache expire: %s (cache ID %s)', $okey, $key), 'DEBUG'); } return true; } catch (MongoException $e) { return false; } } /** */ public function clear() { $this->_db->drop(); } /** * Gets the cache ID for a key. * * @param string $key The key. * * @return string The cache ID. */ protected function _getCid($key) { return hash('md5', $key); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Null.php0000664000175000017500000000203413054773062017622 0ustar janjan * @category Horde * @copyright 2006-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Null extends Horde_Cache_Storage_Base { /** */ public function get($key, $lifetime = 0) { return false; } /** */ public function set($key, $data, $lifetime = 0) { } /** */ public function exists($key, $lifetime = 0) { return false; } /** */ public function expire($key) { return false; } /** */ public function clear() { } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Session.php0000664000175000017500000000473713054773062020347 0ustar janjan * @category Horde * @copyright 2010-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Session extends Horde_Cache_Storage_Base { /** * Pointer to the session entry. * * @var array */ protected $_sess; /** * Constructor. * * @param array $params Optional parameters: *
     *   - session: (string) Store session data in this entry.
     *              DEFAULT: 'horde_cache_session'
     * 
*/ public function __construct(array $params = array()) { $params = array_merge(array( 'sess_name' => 'horde_cache_session' ), $params); parent::__construct($params); } /** * Do initialization tasks. */ protected function _initOb() { if (!isset($_SESSION[$this->_params['sess_name']])) { $_SESSION[$this->_params['sess_name']] = array(); } $this->_sess = &$_SESSION[$this->_params['sess_name']]; } /** */ public function get($key, $lifetime = 0) { return $this->exists($key, $lifetime) ? $this->_sess[$key]['d'] : false; } /** */ public function set($key, $data, $lifetime = 0) { $this->_sess[$key] = array( 'd' => $data, 'l' => $lifetime ); } /** */ public function exists($key, $lifetime = 0) { if (isset($this->_sess[$key])) { /* 0 means no expire. */ if (($lifetime == 0) || ((time() - $lifetime) <= $this->_sess[$key]['l'])) { return true; } unset($this->_sess[$key]); } return false; } /** */ public function expire($key) { if (isset($this->_sess[$key])) { unset($this->_sess[$key]); return true; } return false; } /** */ public function clear() { $this->_sess = array(); } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Sql.php0000664000175000017500000001504413054773062017454 0ustar janjan * CREATE TABLE horde_cache ( * cache_id VARCHAR(32) NOT NULL, * cache_timestamp BIGINT NOT NULL, * cache_data LONGBLOB, * (Or on PostgreSQL:) * cache_data TEXT, * (Or on some other DBMS systems:) * cache_data IMAGE, * * PRIMARY KEY (cache_id) * ); * * * @author Ben Klang * @author Michael Slusarz * @category Horde * @copyright 2007-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Sql extends Horde_Cache_Storage_Base { /** * Handle for the current database connection. * * @var Horde_Db_Adapter */ protected $_db; /** * Constructor. * * @param array $params Parameters: *
     *   - db: (Horde_Db_Adapter) [REQUIRED] The DB instance.
     *   - table: (string) The name of the cache table.
     *            DEFAULT: 'horde_cache'
     * 
*/ public function __construct($params = array()) { if (!isset($params['db'])) { throw new InvalidArgumentException('Missing db parameter.'); } parent::__construct(array_merge(array( 'table' => 'horde_cache', ), $params)); } /** */ protected function _initOb() { $this->_db = $this->_params['db']; } /** * Destructor. */ public function __destruct() { /* Only do garbage collection 0.1% of the time we create an object. */ if (substr(time(), -3) !== '000') { return; } $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_expiration < ? AND cache_expiration <> 0'; $values = array(time()); try { $this->_db->delete($query, $values); } catch (Horde_Db_Exception $e) {} } /** */ public function get($key, $lifetime = 0) { $okey = $key; $key = hash('md5', $key); $timestamp = time(); $maxage = $timestamp - $lifetime; /* Build SQL query. */ $query = 'SELECT cache_data FROM ' . $this->_params['table'] . ' WHERE cache_id = ?'; $values = array($key); // 0 lifetime checks for objects which have no expiration if ($lifetime != 0) { $query .= ' AND cache_timestamp >= ?'; $values[] = $maxage; } try { $result = $this->_db->selectValue($query, $values); $columns = $this->_db->columns($this->_params['table']); } catch (Horde_Db_Exception $e) { return false; } if (!$result) { /* No rows were found - cache miss */ if ($this->_logger) { $this->_logger->log(sprintf('Cache miss: %s (Id %s newer than %d)', $okey, $key, $maxage), 'DEBUG'); } return false; } if ($this->_logger) { $this->_logger->log(sprintf('Cache hit: %s (Id %s newer than %d)', $okey, $key, $maxage), 'DEBUG'); } return $columns['cache_data']->binaryToString($result); } /** */ public function set($key, $data, $lifetime = 0) { $okey = $key; $key = hash('md5', $key); $timestamp = time(); // 0 lifetime indicates the object should not be GC'd. $expiration = ($lifetime === 0) ? 0 : ($lifetime + $timestamp); if ($this->_logger) { $this->_logger->log(sprintf('Cache set: %s (Id %s set at %d expires at %d)', $okey, $key, $timestamp, $expiration), 'DEBUG'); } // Remove any old cache data and prevent duplicate keys $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id = ?'; $values = array($key); try { $this->_db->delete($query, $values); } catch (Horde_Db_Exception $e) {} /* Build SQL query. */ $values = array( 'cache_id' => $key, 'cache_timestamp' => $timestamp, 'cache_expiration' => $expiration, 'cache_data' => new Horde_Db_Value_Binary($data) ); try { $this->_db->insertBlob($this->_params['table'], $values); } catch (Horde_Db_Exception $e) { throw new Horde_Cache_Exception($e); } } /** */ public function exists($key, $lifetime = 0) { $okey = $key; $key = hash('md5', $key); /* Build SQL query. */ $query = 'SELECT 1 FROM ' . $this->_params['table'] . ' WHERE cache_id = ?'; $values = array($key); // 0 lifetime checks for objects which have no expiration if ($lifetime != 0) { $query .= ' AND cache_timestamp >= ?'; $values[] = time() - $lifetime; } try { $result = $this->_db->selectValue($query, $values); } catch (Horde_Db_Exception $e) { return false; } $timestamp = time(); if (empty($result)) { if ($this->_logger) { $this->_logger->log(sprintf('Cache exists() miss: %s (Id %s newer than %d)', $okey, $key, $timestamp), 'DEBUG'); } return false; } if ($this->_logger) { $this->_logger->log(sprintf('Cache exists() hit: %s (Id %s newer than %d)', $okey, $key, $timestamp), 'DEBUG'); } return true; } /** */ public function expire($key) { $key = hash('md5', $key); $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id = ?'; $values = array($key); try { $this->_db->delete($query, $values); } catch (Horde_Db_Exception $e) { return false; } return true; } /** */ public function clear() { $query = 'DELETE FROM ' . $this->_params['table']; try { $this->_db->delete($query); } catch (Horde_Db_Exception $e) { throw new Horde_Cache_Exception($e); } } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Stack.php0000664000175000017500000000622413054773062017762 0ustar janjan * @category Horde * @copyright 2010-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Stack extends Horde_Cache_Storage_Base { /** * Stack of cache drivers. * * @var string */ protected $_stack = array(); /** * Constructor. * * @param array $params Parameters: *
     *   - stack: (array) [REQUIRED] An array of storage instances to loop
     *            through, in order of priority. The last entry is considered
     *            the 'master' driver, for purposes of writes.
     * 
*/ public function __construct(array $params = array()) { if (!isset($params['stack'])) { throw new InvalidArgumentException('Missing stack parameter.'); } parent::__construct($params); } /** */ protected function _initOb() { $this->_stack = array_values($this->_params['stack']); } /** */ public function get($key, $lifetime = 0) { foreach ($this->_stack as $val) { if (($result = $val->get($key, $lifetime)) !== false) { return $result; } } return false; } /** */ public function set($key, $data, $lifetime = 0) { /* Do writes in *reverse* order, since a failure on the master should * not allow writes on the other backends. */ foreach (array_reverse($this->_stack) as $k => $v) { if (($result = $v->set($key, $data, $lifetime)) === false) { if ($k === 0) { return; } /* Invalidate cache if write failed. */ $val->expire($k); } } } /** */ public function exists($key, $lifetime = 0) { foreach ($this->_stack as $val) { if (($result = $val->exists($key, $lifetime)) === true) { break; } } return $result; } /** */ public function expire($key) { foreach ($this->_stack as $val) { $success = $val->expire($key); } /* Success is reported from last (master) expire() call. */ return $success; } /** */ public function clear() { foreach ($this->_stack as $val) { try { $val->clear(); $ex = null; } catch (Horde_Cache_Exception $e) { $ex = $e; } } if ($ex) { throw $ex; } } } Horde_Cache-2.5.5/lib/Horde/Cache/Storage/Xcache.php0000664000175000017500000000524413054773062020111 0ustar janjan * @category Horde * @copyright 2006-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Storage_Xcache extends Horde_Cache_Storage_Base { /** * Constructor. * * @param array $params Optional parameters: *
     *   - prefix: (string) The prefix to use for the cache keys.
     *             DEFAULT: ''
     * 
*/ public function __construct(array $params = array()) { parent::__construct(array_merge(array( 'prefix' => '', ), $params)); } /** */ public function get($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); $result = xcache_get($key); return empty($result) ? false : $result; } /** */ public function set($key, $data, $lifetime = 0) { $key = $this->_params['prefix'] . $key; if (xcache_set($key . '_expire', time(), $lifetime)) { xcache_set($key, $data, $lifetime); } } /** */ public function exists($key, $lifetime = 0) { $key = $this->_params['prefix'] . $key; $this->_setExpire($key, $lifetime); return xcache_isset($key); } /** */ public function expire($key) { $key = $this->_params['prefix'] . $key; xcache_unset($key . '_expire'); return xcache_unset($key); } /** */ public function clear() { // xcache_clear_cache() won't work because it requires HTTP Auth. throw new Horde_Cache_Exception('Not supported'); } /** * Set expire time on each call since xcache sets it on cache creation. * * @param string $key Cache key to expire. * @param integer $lifetime Lifetime of the data in seconds. */ protected function _setExpire($key, $lifetime) { if ($lifetime == 0) { // don't expire return; } $expire = xcache_get($key . '_expire'); // set prune period if ($expire + $lifetime < time()) { // Expired xcache_unset($key . '_expire'); xcache_unset($key); } } } Horde_Cache-2.5.5/lib/Horde/Cache/Exception.php0000664000175000017500000000065113054773062017245 0ustar janjan * @category Horde * @package Cache */ class Horde_Cache_Exception extends Horde_Exception_Wrapped { } Horde_Cache-2.5.5/lib/Horde/Cache.php0000664000175000017500000001247413054773062015315 0ustar janjan * @author Chuck Hagenbuch * @author Michael Slusarz * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class provides the API interface to the cache storage drivers. * * @author Anil Madhavapeddy * @author Chuck Hagenbuch * @author Michael Slusarz * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache { /** * Cache parameters. * * @var array */ protected $_params = array( 'compress' => false, 'lifetime' => 86400 ); /** * Logger. * * @var Horde_Log_Logger */ protected $_logger; /** * Storage object. * * @var Horde_Cache_Storage */ protected $_storage; /** * Constructor. * * @param Horde_Cache_Storage $storage The storage object. * @param array $params Parameter array: *
     *   - compress: (boolean) Compress data (if possible)?
     *               DEFAULT: false
     *   - lifetime: (integer) Lifetime of data, in seconds.
     *               DEFAULT: 86400 seconds
     *   - logger: (Horde_Log_Logger) Log object to use for log/debug messages.
     * 
*/ public function __construct(Horde_Cache_Storage_Base $storage, array $params = array()) { if (isset($params['logger'])) { $this->_logger = $params['logger']; unset($params['logger']); $storage->setLogger($this->_logger); } $this->_params = array_merge($this->_params, $params); $this->_storage = $storage; } /** * Attempts to directly output a cached object. * * @todo Change default lifetime to 0 * * @param string $key Object ID to query. * @param integer $lifetime Lifetime of the object in seconds. * * @return boolean True if output or false if no object was found. */ public function output($key, $lifetime = 1) { $data = $this->get($key, $lifetime); if ($data === false) { return false; } echo $data; return true; } /** * Retrieve cached data. * * @todo Change default lifetime to 0 * * @param string $key Object ID to query. * @param integer $lifetime Lifetime of the object in seconds. * * @return mixed Cached data, or false if none was found. */ public function get($key, $lifetime = 1) { $res = $this->_storage->get($key, $lifetime); if (empty($this->_params['compress']) || !is_string($res)) { return $res; } $compress = new Horde_Compress_Fast(); return $compress->decompress($res); } /** * Store an object in the cache. * * @param string $key Object ID used as the caching key. * @param string $data Data to store in the cache. * @param integer $lifetime Object lifetime - i.e. the time before the * data becomes available for garbage * collection, in seconds. If null use the * default Horde GC time. If 0 will not be GC'd. */ public function set($key, $data, $lifetime = null) { if (!empty($this->_params['compress'])) { $compress = new Horde_Compress_Fast(); $data = $compress->compress($data); } $lifetime = is_null($lifetime) ? $this->_params['lifetime'] : $lifetime; $this->_storage->set($key, $data, $lifetime); } /** * Checks if a given key exists in the cache, valid for the given * lifetime. * * @todo Change default lifetime to 0 * * @param string $key Cache key to check. * @param integer $lifetime Lifetime of the key in seconds. * * @return boolean Existence. */ public function exists($key, $lifetime = 1) { return $this->_storage->exists($key, $lifetime); } /** * Expire any existing data for the given key. * * @param string $key Cache key to expire. * * @return boolean Success or failure. */ public function expire($key) { return $this->_storage->expire($key); } /** * Clears all data from the cache. * * @throws Horde_Cache_Exception */ public function clear() { return $this->_storage->clear(); } /** * Tests the driver for read/write access. * * @return boolean True if read/write is available. */ public function testReadWrite() { $key = '__horde_cache_testkey'; try { $this->_storage->set($key, 1); if ($this->_storage->exists($key)) { $this->_storage->expire($key); return true; } } catch (Exception $e) {} return false; } } Horde_Cache-2.5.5/migration/Horde/Cache/1_horde_cache_base_tables.php0000664000175000017500000000132413054773062023520 0ustar janjantables())) { $t = $this->createTable('horde_cache', array('autoincrementKey' => array('cache_id'))); $t->column('cache_id', 'string', array('limit' => 32, 'null' => false)); $t->column('cache_timestamp', 'bigint', array('null' => false)); $t->column('cache_expiration', 'bigint', array('null' => false)); $t->column('cache_data', 'binary'); $t->end(); } } public function down() { $this->dropTable('horde_cache'); } } Horde_Cache-2.5.5/migration/Horde/Cache/2_horde_cache_fix_blob_length.php0000664000175000017500000000033113054773062024377 0ustar janjanchangeColumn('horde_cache', 'cache_data', 'binary'); } public function down() { } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/Pdo/MysqlTest.php0000664000175000017500000000241513054773062020746 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class test a PDO MySQL backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_Pdo_MysqlTest extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { if (!extension_loaded('pdo') || !in_array('mysql', PDO::getAvailableDrivers())) { $this->reason = 'No pdo_mysql extension'; return; } $config = self::getConfig('CACHE_SQL_PDO_MYSQL_TEST_CONFIG', __DIR__ . '/../..'); if ($config && !empty($config['cache']['sql']['pdo_mysql'])) { $this->db = new Horde_Db_Adapter_Pdo_Mysql($config['cache']['sql']['pdo_mysql']); return parent::_getCache($params); } else { $this->reason = 'No pdo_mysql configuration'; } } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/Pdo/PgsqlTest.php0000664000175000017500000000242213054773062020725 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class test a PDO PostgreSQL backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_Pdo_PgsqlTest extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { if (!extension_loaded('pdo') || !in_array('pgsql', PDO::getAvailableDrivers())) { $this->reason = 'No pdo_pgsql extension'; return; } $config = self::getConfig('CACHE_SQL_PDO_PGSQL_TEST_CONFIG', __DIR__ . '/../..'); if ($config && !empty($config['cache']['sql']['pdo_pgsql'])) { $this->db = new Horde_Db_Adapter_Pdo_Pgsql($config['cache']['sql']['pdo_pgsql']); return parent::_getCache($params); } else { $this->reason = 'No pdo_pgsql configuration'; } } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/Pdo/SqliteTest.php0000664000175000017500000000171113054773062021100 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class test a PDO SQLite backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_Pdo_SqliteTest extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { $factory_db = new Horde_Test_Factory_Db(); try { $this->db = $factory_db->create(); } catch (Horde_Test_Exception $e) { $this->reason = 'Sqlite not available'; return; } return parent::_getCache($params); } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/Base.php0000664000175000017500000000355613054773062017140 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This is the base test class for all SQL backends. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_Base extends Horde_Cache_TestBase { protected function _getCache($params = array()) { $logger = new Horde_Log_Logger(new Horde_Log_Handler_Cli()); //$this->db->setLogger($logger); $dir = __DIR__ . '/../../../../migration/Horde/Cache'; if (!is_dir($dir)) { error_reporting(E_ALL & ~E_DEPRECATED); $dir = PEAR_Config::singleton() ->get('data_dir', null, 'pear.horde.org') . '/Horde_Cache/migration'; error_reporting(E_ALL | E_STRICT); } $this->migrator = new Horde_Db_Migration_Migrator( $this->db, null,//$logger, array('migrationsPath' => $dir, 'schemaTableName' => 'horde_cache_schema_info')); $this->migrator->up(); return new Horde_Cache( new Horde_Cache_Storage_File(array_merge( array('db' => $this->db), $params )) ); } public function tearDown() { parent::tearDown(); $this->db->delete('DELETE FROM horde_cache'); if ($this->migrator) { $this->migrator->down(); } if ($this->db) { $this->db->disconnect(); } $this->db = $this->migrator = null; } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/MysqliTest.php0000664000175000017500000000227013054773062020374 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests a MySQLi backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_MysqliTest extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { if (!extension_loaded('mysqli')) { $this->reason = 'No mysqli extension'; return; } $config = self::getConfig('CACHE_SQL_MYSQLI_TEST_CONFIG', __DIR__ . '/..'); if ($config && !empty($config['cache']['sql']['mysqli'])) { $this->db = new Horde_Db_Adapter_Mysqli($config['cache']['sql']['mysqli']); return parent::_getCache($params); } else { $this->reason = 'No mysqli configuration'; } } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/MysqlTest.php0000664000175000017500000000225713054773062020230 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests a MySQL backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_MysqlTest extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { if (!extension_loaded('mysql')) { $this->reason = 'No mysql extension'; return; } $config = self::getConfig('CACHE_SQL_MYSQL_TEST_CONFIG', __DIR__ . '/..'); if ($config && !empty($config['cache']['sql']['mysql'])) { $this->db = new Horde_Db_Adapter_Mysql($config['cache']['sql']['mysql']); return parent::_getCache($params); } else { $this->reason = 'No mysql configuration'; } } } Horde_Cache-2.5.5/test/Horde/Cache/Sql/Oci8Test.php0000664000175000017500000000225113054773062017717 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests an Oracle backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Sql_Oci8Test extends Horde_Cache_Sql_Base { protected function _getCache($params = array()) { if (!extension_loaded('oci8')) { $this->reason = 'No oci8 extension'; return; } $config = self::getConfig('CACHE_SQL_OCI8_TEST_CONFIG', __DIR__ . '/..'); if ($config && !empty($config['cache']['sql']['oci8'])) { $this->db = new Horde_Db_Adapter_Oci8($config['cache']['sql']['oci8']); return parent::_getCache($params); } else { $this->reason = 'No oci8 configuration'; } } } Horde_Cache-2.5.5/test/Horde/Cache/Stub/File.php0000664000175000017500000000140213054773062017307 0ustar janjan * @category Horde * @copyright 2016-2017 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_Stub_File extends Horde_Cache_Storage_File { /** * Enforces garbage collection. */ public function gc() { $this->_gc(); } } Horde_Cache-2.5.5/test/Horde/Cache/AllTests.php0000664000175000017500000000013213054773062017245 0ustar janjanrun(); Horde_Cache-2.5.5/test/Horde/Cache/ApcTest.php0000664000175000017500000000166713054773062017073 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the APC backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_ApcTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!extension_loaded('apc')) { $this->reason = 'APC extension not loaded'; return; } return new Horde_Cache( new Horde_Cache_Storage_Apc(array( 'prefix' => 'horde_cache_test' )) ); } } Horde_Cache-2.5.5/test/Horde/Cache/bootstrap.php0000664000175000017500000000014313054773062017531 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the eAccelerator backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_EacceleratorTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!extension_loaded('eaccelerator')) { $this->reason = 'eAccelerator extension not loaded'; return; } if (!function_exists('eaccelerator_gc')) { $this->reason = 'eAccelerator must be compiled with support for shared memory to use as caching backend.'; return; } return new Horde_Cache( new Horde_Cache_Storage_Eaccelerator(array( 'prefix' => 'horde_cache_test' )) ); } } Horde_Cache-2.5.5/test/Horde/Cache/FileTest.php0000664000175000017500000001317313054773062017242 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the file backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_FileTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { $this->dir = sys_get_temp_dir() . '/horde_cache_test'; if (!is_dir($this->dir)) { mkdir($this->dir); } return new Horde_Cache( new Horde_Cache_Storage_File(array_merge( array( 'dir' => $this->dir, 'no_gc' => true, 'prefix' => 'horde_cache_test' ), $params )) ); } public function testSubdirectories() { $this->cache = $this->_getCache(array('sub' => 2)); if (!$this->cache) { $this->markTestSkipped($this->reason); } $this->assertNull($this->cache->set('key1', 'data1', 0)); $this->assertNull($this->cache->set('key2', 'data2', 0)); $this->assertEquals( array($this->dir . '/7/', $this->dir . '/c/'), glob($this->dir . '/*', GLOB_MARK) ); $this->assertEquals( array($this->dir . '/7/8/'), glob($this->dir . '/7/*', GLOB_MARK) ); $this->assertEquals( array($this->dir . '/c/2/'), glob($this->dir . '/c/*', GLOB_MARK) ); $this->assertEquals( array($this->dir . '/7/8/horde_cache_test78f825aaa0103319aaa1a30bf4fe3ada'), glob($this->dir . '/7/8/*', GLOB_MARK) ); $this->assertEquals( array($this->dir . '/c/2/horde_cache_testc2add694bf942dc77b376592d9c862cd'), glob($this->dir . '/c/2/*', GLOB_MARK) ); } public function testMigrateGarbageCollection() { mkdir($this->dir . '/c'); mkdir($this->dir . '/7'); mkdir($this->dir . '/3'); $fp = fopen($this->dir . '/horde_cache_gc', 'w'); $time = time(); fwrite( $fp, $this->dir . "/c/c2add694bf942dc77b376592d9c862cd\t" . ($time - 100) . "\n" ); fwrite( $fp, $this->dir . "/7/78f825aaa0103319aaa1a30bf4fe3ada \t" . ($time + 100) . "\n" ); fwrite( $fp, $this->dir . "/3/3631578538a2d6ba5879b31a9a42f290\t" . ($time - 100) . "\n" ); fwrite( $fp, $this->dir . "/3/3631578538a2d6ba5879b31a9a42f290\t" . ($time + 100) . "\n" ); fwrite( $fp, $this->dir . "/c/caf8e34be07426ae7127c1b4829983c1\t" . ($time + 100) . "\n" ); fwrite( $fp, $this->dir . "/c/caf8e34be07426ae7127c1b4829983c1\t" . ($time - 100) . "\n" ); fclose($fp); $storage = new Horde_Cache_Stub_File(array( 'dir' => $this->dir, 'no_gc' => true, 'prefix' => 'horde_cache_test', 'sub' => 1 )); $this->cache = new Horde_Cache($storage); $storage->gc(); $this->assertFileExists($this->dir . '/7/horde_cache_gc'); $this->assertStringEqualsFile( $this->dir . '/7/horde_cache_gc', $this->dir . "/7/78f825aaa0103319aaa1a30bf4fe3ada \t" . ($time + 100) . "\n" ); $this->assertFileExists($this->dir . '/3/horde_cache_gc'); $this->assertStringEqualsFile( $this->dir . '/3/horde_cache_gc', $this->dir . "/3/3631578538a2d6ba5879b31a9a42f290\t" . ($time + 100) . "\n" ); $this->assertFileExists($this->dir . '/c/horde_cache_gc'); $this->assertStringEqualsFile( $this->dir . '/c/horde_cache_gc', $this->dir . "/c/c2add694bf942dc77b376592d9c862cd\t" . ($time - 100) . "\n" . $this->dir . "/c/caf8e34be07426ae7127c1b4829983c1\t" . ($time - 100) . "\n" ); $this->assertFileNotExists($this->dir . '/horde_cache_gc'); } public function testGarbageCollection() { $storage = new Horde_Cache_Stub_File(array( 'dir' => $this->dir, 'no_gc' => true, 'prefix' => 'horde_cache_test', 'sub' => 2, )); $this->cache = new Horde_Cache($storage); $this->cache->set('key1', 'data1', -100); $this->cache->set('key2', 'data2', 100); $this->cache->set('key3', 'data3', -100); $this->cache->set('key3', 'data4', 100); $this->cache->set('key4', 'data5', 100); $this->cache->set('key4', 'data6', -100); $storage->gc(); $this->assertFileExists($this->dir . '/7/8/horde_cache_test78f825aaa0103319aaa1a30bf4fe3ada'); $this->assertFileExists($this->dir . '/3/6/horde_cache_test3631578538a2d6ba5879b31a9a42f290'); $this->assertFileNotExists($this->dir . '/c/2/horde_cache_testc2add694bf942dc77b376592d9c862cd'); $this->assertFileNotExists($this->dir . '/c/a/horde_cache_testcaf8e34be07426ae7127c1b4829983c1'); } public function tearDown() { parent::tearDown(); system('rm -r ' . $this->dir); } } Horde_Cache-2.5.5/test/Horde/Cache/HashtableTest.php0000664000175000017500000000204013054773062020245 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the Horde_Hashtable backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_HashtableTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!class_exists('Horde_HashTable_Memory')) { $this->reason = 'Horde_HashTable not installed'; return; } return new Horde_Cache( new Horde_Cache_Storage_Hashtable(array( 'hashtable' => new Horde_HashTable_Memory(), 'prefix' => 'horde_cache_test' )) ); } } Horde_Cache-2.5.5/test/Horde/Cache/MemcacheTest.php0000664000175000017500000000265513054773062020070 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the Memcache backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_MemcacheTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!class_exists('Horde_Memcache')) { $this->reason = 'Horde_Memcache not installed'; return; } if (!(extension_loaded('memcache') || extension_loaded('memcached'))) { $this->reason = 'Memcache extension not loaded'; return; } if (!($config = self::getConfig('CACHE_MEMCACHE_TEST_CONFIG')) || !isset($config['cache']['memcache'])) { $this->reason = 'Memcache configuration not available.'; return; } return new Horde_Cache( new Horde_Cache_Storage_Memcache(array( 'memcache' => new Horde_Memcache($config['cache']['memcache']), 'prefix' => 'horde_cache_test' )) ); } } Horde_Cache-2.5.5/test/Horde/Cache/MemoryTest.php0000664000175000017500000000264713054773062017637 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the memory backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_MemoryTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { return new Horde_Cache( new Horde_Cache_Storage_Memory() ); } /** * The Memory backend doesn't support lifetimes, so cannot test these like * in the TestBase class. */ public function testExists() { $this->assertFalse($this->cache->exists('key1', 0)); $this->cache->set('key1', 'data1', 0); $this->assertTrue($this->cache->exists('key1', 0)); } /** * The Memory backend doesn't support lifetimes, so cannot test these like * in the TestBase class. */ public function testGet() { $this->assertFalse($this->cache->get('key1', 0)); $this->cache->set('key1', 'data1', 0); $this->assertEquals('data1', $this->cache->get('key1', 0)); } } Horde_Cache-2.5.5/test/Horde/Cache/MongoTest.php0000664000175000017500000000372013054773062017437 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the MongoDB backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_MongoTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!extension_loaded('mongo') && !extension_loaded('mongodb')) { $this->reason = 'Mongo/Mongodb extensions not loaded'; return; } if (!class_exists('Horde_Mongo_Client')) { $this->reason = 'Horde_Mongo not installed'; return; } if (!($config = self::getConfig('CACHE_MONGO_TEST_CONFIG', __DIR__)) || !isset($config['cache']['mongo']['hostspec'])) { $this->reason = 'Mongo configuration not available'; return; } $factory = new Horde_Test_Factory_Mongo(); $this->mongo = $factory->create(array( 'config' => $config['cache']['mongo']['hostspec'], 'dbname' => 'horde_cache_test' )); if (!$this->mongo) { $this->reason = 'MongoDB not available.'; return; } $storage = new Horde_Cache_Storage_Mongo(array( 'mongo_db' => $this->mongo, 'collection' => 'horde_cache_test' )); //$storage->setLogger(new Horde_Log_Logger(new Horde_Log_Handler_Cli())); return new Horde_Cache($storage); } public function tearDown() { parent::tearDown(); if (!empty($this->mongo)) { $this->mongo->selectDB(null)->drop(); } } } Horde_Cache-2.5.5/test/Horde/Cache/phpunit.xml0000664000175000017500000000005613054773062017217 0ustar janjan Horde_Cache-2.5.5/test/Horde/Cache/SessionTest.php0000664000175000017500000000140213054773062017776 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the session backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_SessionTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { return new Horde_Cache( new Horde_Cache_Storage_Session() ); } } Horde_Cache-2.5.5/test/Horde/Cache/TestBase.php0000664000175000017500000000704413054773062017235 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This is the base test class to run all tests that the backend implementation * should support. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ abstract class Horde_Cache_TestBase extends Horde_Test_Case { protected $reason = ''; protected $cache; abstract protected function _getCache($params = array()); public function setUp() { $this->cache = $this->_getCache(); if (!$this->cache) { $this->markTestSkipped($this->reason); } } public function testReadWrite() { $this->assertTrue($this->cache->testReadWrite()); } public function testSet() { $this->assertNull($this->cache->set('key1', 'data1')); $this->assertNull($this->cache->set('key2', 'data2', 0)); $this->assertNull($this->cache->set('key3', 'data3', 1)); } public function testExists() { $this->assertFalse($this->cache->exists('key1', 0)); $this->assertFalse($this->cache->exists('key2', 0)); $this->cache->set('key1', 'data1', 0); $this->cache->set('key2', 'data2', 0); $this->assertTrue($this->cache->exists('key1', 0)); $this->assertFalse($this->cache->exists('key2', -10)); } public function testGet() { $this->assertFalse($this->cache->get('key1', 0)); $this->assertFalse($this->cache->get('key2', 0)); $this->cache->set('key1', 'data1', 0); $this->cache->set('key2', 'data2', 0); $this->assertEquals('data1', $this->cache->get('key1', 0)); $this->assertFalse($this->cache->get('key2', -10)); } public function testOutput() { $this->markTestSkipped(); $this->assertFalse($this->cache->output('key1', 0)); $this->cache->set('key1', 'data1', 0); ob_start(); $this->assertTrue($this->cache->output('key1', 0)); $this->assertEquals('data1', ob_get_contents()); ob_end_clean(); } public function testExpire() { $this->cache->set('key1', 'data1', 0); $this->assertEquals('data1', $this->cache->get('key1', 0)); $this->cache->expire('key1'); $this->assertFalse($this->cache->get('key1', 0)); } public function testClear() { $this->cache->set('key1', 'data1', 0); $this->assertEquals('data1', $this->cache->get('key1', 0)); $this->cache->clear(); $this->assertFalse($this->cache->get('key1', 0)); } public function testCompress() { if (!class_exists('Horde_Compress_Fast')) { $this->markTestSkipped('Horde_Compress_Fast not installed'); } $this->tearDown(); $this->cache = $this->_getCache(array('compress' => true)); if (!$this->cache) { $this->markTestSkipped($this->reason); } $this->assertFalse($this->cache->get('key1', 0)); $this->cache->set('key1', 'data1', 0); $this->assertEquals('data1', $this->cache->get('key1', 0)); } public function tearDown() { if ($this->cache) { $this->cache->clear(); unset($this->cache); } } } Horde_Cache-2.5.5/test/Horde/Cache/XcacheTest.php0000664000175000017500000000235313054773062017554 0ustar janjan * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ /** * This class tests the XCache backend. * * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Cache */ class Horde_Cache_XcacheTest extends Horde_Cache_TestBase { protected function _getCache($params = array()) { if (!extension_loaded('xcache')) { $this->reason = 'XCache extension not loaded'; return; } return new Horde_Cache( new Horde_Cache_Storage_Xcache(array( 'prefix' => 'horde_cache_test' )) ); } public function testClear() { $this->markTestSkipped('Not supported'); } public function tearDown() { if ($this->cache) { $this->cache->expire('key1'); $this->cache->expire('key2'); unset($this->cache); } } }