message_cache.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 message generated response message if the message entry
  50. /// can be found.
  51. ///
  52. /// \return return true if the message can be found in cache, or else,
  53. /// return false.
  54. //TODO Maybe some user just want to get the message_entry.
  55. bool lookup(const isc::dns::Name& qname,
  56. const isc::dns::RRType& qtype,
  57. isc::dns::Message& message);
  58. /// \brief Update the message in the cache with the new one.
  59. /// If the message doesn't exist in the cache, it will be added
  60. /// directly.
  61. bool update(const isc::dns::Message& msg);
  62. protected:
  63. /// \brief Get the hash key for the message entry in the cache.
  64. /// \param name query name of the message.
  65. /// \param type query type of the message.
  66. /// \return return the hash key.
  67. HashKey getEntryHashKey(const isc::dns::Name& name,
  68. const isc::dns::RRType& type) const;
  69. // Make these variants be protected for easy unittest.
  70. protected:
  71. uint16_t message_class_; // The class of the message cache.
  72. RRsetCachePtr rrset_cache_;
  73. RRsetCachePtr negative_soa_cache_;
  74. isc::nsas::HashTable<MessageEntry> message_table_;
  75. isc::util::LruList<MessageEntry> message_lru_;
  76. };
  77. typedef boost::shared_ptr<MessageCache> MessageCachePtr;
  78. } // namespace cache
  79. } // namespace isc
  80. #endif // __MESSAGE_CACHE_H