rrset_cache.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. ///
  27. /// \todo The rrset cache class should provide the interfaces for
  28. /// loading, dumping and resizing.
  29. class RRsetCache{
  30. ///
  31. /// \name Constructors and Destructor
  32. ///
  33. /// Note: The copy constructor and the assignment operator are intentionally
  34. /// defined as private to make it uncopyable
  35. //@{
  36. private:
  37. RRsetCache(const RRsetCache&);
  38. RRsetCache& operator=(const RRsetCache&);
  39. public:
  40. /// \brief Constructor and Destructor
  41. ///
  42. /// \param cache_size the size of rrset cache.
  43. /// \param rrset_class the class of rrset cache.
  44. RRsetCache(uint32_t cache_size, uint16_t rrset_class);
  45. virtual ~RRsetCache() {
  46. rrset_lru_.clear(); // Clear the rrset entries in the list.
  47. }
  48. //@}
  49. /// \brief Look up rrset in cache.
  50. ///
  51. /// \param qname The query name to look up
  52. /// \param qtype The query type
  53. /// \return return the shared_ptr of rrset entry if it can be
  54. /// found in the cache, or else, return NULL.
  55. RRsetEntryPtr lookup(const isc::dns::Name& qname,
  56. const isc::dns::RRType& qtype);
  57. /// \brief Update RRset Cache
  58. /// Update the rrset entry in the cache with the new one.
  59. /// If the rrset has expired or doesn't exist in the cache,
  60. /// it will be added directly. It may be ingored if the new
  61. /// rrset is not more authoritative than the old rrset in cache.
  62. ///
  63. /// \param rrset The new rrset used to update cache.
  64. /// \param level trustworthiness of the rrset.
  65. /// \return return the rrset entry in the cache, it may be the
  66. /// new added rrset entry or existed one if it is not replaced.
  67. RRsetEntryPtr update(const isc::dns::RRset& rrset,
  68. const RRsetTrustLevel& level);
  69. /// \short Protected memebers, so they can be accessed by tests.
  70. protected:
  71. uint16_t class_; // The class of the rrset cache.
  72. isc::nsas::HashTable<RRsetEntry> rrset_table_;
  73. isc::util::LruList<RRsetEntry> rrset_lru_;
  74. };
  75. typedef boost::shared_ptr<RRsetCache> RRsetCachePtr;
  76. typedef boost::shared_ptr<const RRsetCache> ConstRRsetCachePtr;
  77. } // namespace cache
  78. } // namespace isc
  79. #endif // __RRSET_CACHE_H