message_cache.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 __MESSAGE_CACHE_H
  15. #define __MESSAGE_CACHE_H
  16. #include <string>
  17. #include <boost/shared_ptr.hpp>
  18. #include <dns/message.h>
  19. #include "message_entry.h"
  20. #include <nsas/hash_table.h>
  21. #include <util/lru_list.h>
  22. #include "rrset_cache.h"
  23. namespace isc {
  24. namespace cache {
  25. /// \brief Message Cache
  26. /// The object of MessageCache represents the cache for class-specific
  27. /// messages.
  28. ///
  29. /// \todo The message cache class should provide the interfaces for
  30. /// loading, dumping and resizing.
  31. class MessageCache {
  32. // Noncopyable
  33. private:
  34. MessageCache(const MessageCache& source);
  35. MessageCache& operator=(const MessageCache& source);
  36. public:
  37. /// \param rrset_cache The cache that stores the RRsets that the
  38. /// message entry will point to
  39. /// \param cache_size The size of message cache.
  40. /// \param message_class The class of the message cache
  41. /// \param negative_soa_cache The cache that stores the SOA record
  42. /// that comes from negative response message
  43. MessageCache(const RRsetCachePtr& rrset_cache,
  44. uint32_t cache_size, uint16_t message_class,
  45. const RRsetCachePtr& negative_soa_cache);
  46. /// \brief Destructor function
  47. virtual ~MessageCache();
  48. /// \brief Look up message in cache.
  49. /// \param qname Name of the domain for which the message is being sought.
  50. /// \param qtype Type of the RR for which the message is being sought.
  51. /// \param message generated response message if the message entry
  52. /// can be found.
  53. ///
  54. /// \return return true if the message can be found in cache, or else,
  55. /// return false.
  56. //TODO Maybe some user just want to get the message_entry.
  57. bool lookup(const isc::dns::Name& qname,
  58. const isc::dns::RRType& qtype,
  59. isc::dns::Message& message);
  60. /// \brief Update the message in the cache with the new one.
  61. /// If the message doesn't exist in the cache, it will be added
  62. /// directly.
  63. bool update(const isc::dns::Message& msg);
  64. protected:
  65. /// \brief Get the hash key for the message entry in the cache.
  66. /// \param name query name of the message.
  67. /// \param type query type of the message.
  68. /// \return return the hash key.
  69. HashKey getEntryHashKey(const isc::dns::Name& name,
  70. const isc::dns::RRType& type) const;
  71. // Make these variants be protected for easy unittest.
  72. protected:
  73. uint16_t message_class_; // The class of the message cache.
  74. RRsetCachePtr rrset_cache_;
  75. RRsetCachePtr negative_soa_cache_;
  76. isc::nsas::HashTable<MessageEntry> message_table_;
  77. isc::util::LruList<MessageEntry> message_lru_;
  78. };
  79. typedef boost::shared_ptr<MessageCache> MessageCachePtr;
  80. } // namespace cache
  81. } // namespace isc
  82. #endif // __MESSAGE_CACHE_H