TDE network applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * cache.h - (c) 2003 Frerich Raabe <raabe@kde.org>
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef CACHE_H
  26. #define CACHE_H
  27. #include <tqcstring.h>
  28. #include <tqdatetime.h>
  29. #include <tqdict.h>
  30. #include <xmlrpciface.h>
  31. class CacheEntry
  32. {
  33. friend class Cache;
  34. friend TQDataStream &operator>>( TQDataStream &s, CacheEntry &e );
  35. public:
  36. const TQDateTime &timeStamp() const { return m_timeStamp; }
  37. const KXMLRPC::Query::Result result() const { return m_result; }
  38. bool isValid() const;
  39. private:
  40. TQDateTime m_timeStamp;
  41. KXMLRPC::Query::Result m_result;
  42. };
  43. class Cache : public TQDict<CacheEntry>
  44. {
  45. public:
  46. static Cache &self();
  47. static TQString getCacheKey( const TQString &server,
  48. const TQString &method,
  49. const TQValueList<TQVariant> &args );
  50. void load();
  51. void save();
  52. void touch( const TQString &key );
  53. void insert( const TQString &key, const KXMLRPC::Query::Result &result );
  54. private:
  55. Cache();
  56. Cache( const Cache &rhs ); // disabled
  57. Cache &operator=( const Cache &rhs ); // disabled
  58. ~Cache();
  59. TQString cacheFileName() const;
  60. static Cache *m_instance;
  61. };
  62. inline TQDataStream &operator<<( TQDataStream &s, const CacheEntry &e )
  63. {
  64. s << e.timeStamp();
  65. s << e.result();
  66. return s;
  67. }
  68. inline TQDataStream &operator>>( TQDataStream &s, CacheEntry &e )
  69. {
  70. s >> e.m_timeStamp;
  71. s >> e.m_result;
  72. return s;
  73. }
  74. #endif // CACHE_H
  75. // vim:ts=4:sw=4:noet