rrset_cache.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __RRSET_CACHE_H
  15. #define __RRSET_CACHE_H
  16. #include <cache/rrset_entry.h>
  17. #include <nsas/hash_table.h>
  18. #include <util/lru_list.h>
  19. using namespace isc::nsas;
  20. namespace isc {
  21. namespace cache {
  22. class RRsetEntry;
  23. /// \brief RRset Cache
  24. /// The object of RRsetCache represented the cache for class-specific
  25. /// RRsets.
  26. class RRsetCache{
  27. ///
  28. /// \name Constructors and Destructor
  29. ///
  30. /// Note: The copy constructor and the assignment operator are intentionally
  31. /// defined as private to make it uncopyable
  32. //@{
  33. private:
  34. RRsetCache(const RRsetCache&);
  35. RRsetCache& operator=(const RRsetCache&);
  36. public:
  37. /// \brief Constructor and Destructor
  38. ///
  39. /// \param cache_size the size of rrset cache.
  40. /// \param rrset_class the class of rrset cache.
  41. RRsetCache(uint32_t cache_size, uint16_t rrset_class);
  42. virtual ~RRsetCache() {
  43. rrset_lru_.clear(); // Clear the rrset entries in the list.
  44. }
  45. //@}
  46. /// \brief Look up rrset in cache.
  47. ///
  48. /// \param qname The query name to look up
  49. /// \param qtype The query type
  50. /// \return return the shared_ptr of rrset entry if it can be
  51. /// found in the cache, or else, return NULL.
  52. RRsetEntryPtr lookup(const isc::dns::Name& qname,
  53. const isc::dns::RRType& qtype);
  54. /// \brief Update RRset Cache
  55. /// Update the rrset entry in the cache with the new one.
  56. /// If the rrset has expired or doesn't exist in the cache,
  57. /// it will be added directly. It may be ingored if the new
  58. /// rrset is not more authoritative than the old rrset in cache.
  59. ///
  60. /// \param rrset The new rrset used to update cache.
  61. /// \param level trustworthiness of the rrset.
  62. /// \return return the rrset entry in the cache, it may be the
  63. /// new added rrset entry or existed one if it is not replaced.
  64. RRsetEntryPtr update(const isc::dns::RRset& rrset,
  65. const RRsetTrustLevel& level);
  66. #if 0
  67. /// \brief Dump the rrset cache to specified file.
  68. ///
  69. /// \param file_name The file to write to
  70. ///
  71. /// \todo It should can be dumped to one configured database.
  72. void dump(const std::string& file_name);
  73. /// \brief Load the cache from one file.
  74. ///
  75. /// \param file_name The file to read from
  76. ///
  77. /// \todo It should can be loaded from one configured database.
  78. void load(const std::string& file_name);
  79. /// \brief Resize the size of rrset cache in runtime.
  80. ///
  81. /// \param The size to resize to
  82. /// \return true
  83. bool resize(uint32_t size);
  84. #endif
  85. /// \short Protected memebers, so they can be accessed by tests.
  86. protected:
  87. uint16_t class_; // The class of the rrset cache.
  88. isc::nsas::HashTable<RRsetEntry> rrset_table_;
  89. isc::util::LruList<RRsetEntry> rrset_lru_;
  90. };
  91. typedef boost::shared_ptr<RRsetCache> RRsetCachePtr;
  92. typedef boost::shared_ptr<const RRsetCache> ConstRRsetCachePtr;
  93. } // namespace cache
  94. } // namespace isc
  95. #endif // __RRSET_CACHE_H