rrset_cache.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <rrset_entry.h>
  17. #include <nsas/hash_table.h>
  18. #include <nsas/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
  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. ~RRsetCache() {}
  43. //@}
  44. /// \brief Look up rrset in cache.
  45. ///
  46. /// \param qname The query name to look up
  47. /// \param qtype The query type
  48. /// \return return the shared_ptr of rrset entry if it can be
  49. /// found in the cache, or else, return NULL.
  50. RRsetEntryPtr lookup(const isc::dns::Name& qname,
  51. const isc::dns::RRType& qtype);
  52. /// \brief Update RRset Cache
  53. /// Update the rrset entry in the cache with the new one.
  54. /// If the rrset has expired or doesn't exist in the cache,
  55. /// it will be added directly. It may be ingored if the new
  56. /// rrset is not more authoritative than the old rrset in cache.
  57. ///
  58. /// \param rrset The new rrset used to update cache.
  59. /// \param level trustworthiness of the rrset.
  60. /// \return return the rrset entry in the cache, it may be the
  61. /// new added rrset entry or existed one if it is not replaced.
  62. RRsetEntryPtr update(const isc::dns::RRset& rrset,
  63. const RRsetTrustLevel& level);
  64. /// \brief Dump the rrset cache to specified file.
  65. ///
  66. /// \param file_name The file to write to
  67. ///
  68. /// \todo It should can be dumped to one configured database.
  69. void dump(const std::string& file_name);
  70. /// \brief Load the cache from one file.
  71. ///
  72. /// \param file_name The file to read from
  73. ///
  74. /// \todo It should can be loaded from one configured database.
  75. void load(const std::string& file_name);
  76. /// \brief Resize the size of rrset cache in runtime.
  77. ///
  78. /// \param The size to resize to
  79. /// \return true
  80. bool resize(uint32_t size);
  81. private:
  82. uint16_t class_; // The class of the rrset cache.
  83. isc::nsas::HashTable<RRsetEntry> rrset_table_;
  84. isc::nsas::LruList<RRsetEntry> rrset_lru_;
  85. };
  86. typedef boost::shared_ptr<RRsetCache> RRsetCachePtr;
  87. typedef boost::shared_ptr<const RRsetCache> ConstRRsetCachePtr;
  88. } // namespace cache
  89. } // namespace isc
  90. #endif // __RRSET_CACHE_H