rrset_cache.h 3.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#ifndef __RRSET_CACHE_H
#define __RRSET_CACHE_H

18
#include <cache/rrset_entry.h>
19
#include <nsas/hash_table.h>
20 21

#include <util/lru_list.h>
22 23 24 25 26 27 28 29 30 31 32

using namespace isc::nsas;

namespace isc {
namespace cache {

class RRsetEntry;

/// \brief RRset Cache
/// The object of RRsetCache represented the cache for class-specific
/// RRsets.
33 34 35
///
/// \todo The rrset cache class should provide the interfaces for
///       loading, dumping and resizing.
36
class RRsetCache{
37 38 39 40 41 42 43 44 45
    ///
    /// \name Constructors and Destructor
    ///
    /// Note: The copy constructor and the assignment operator are intentionally
    /// defined as private to make it uncopyable
    //@{
private:
    RRsetCache(const RRsetCache&);
    RRsetCache& operator=(const RRsetCache&);
46
public:
47
    /// \brief Constructor and Destructor
48
    ///
49 50 51
    /// \param cache_size the size of rrset cache.
    /// \param rrset_class the class of rrset cache.
    RRsetCache(uint32_t cache_size, uint16_t rrset_class);
52 53 54
    virtual ~RRsetCache() {
        rrset_lru_.clear(); // Clear the rrset entries in the list.
    }
55
    //@}
Ocean Wang's avatar
Ocean Wang committed
56

57
    /// \brief Look up rrset in cache.
58 59 60 61
    ///
    /// \param qname The query name to look up
    /// \param qtype The query type 
    /// \return return the shared_ptr of rrset entry if it can be
62 63 64
    /// found in the cache, or else, return NULL.
    RRsetEntryPtr lookup(const isc::dns::Name& qname,
                         const isc::dns::RRType& qtype);
65

66 67
    /// \brief Update RRset Cache
    /// Update the rrset entry in the cache with the new one.
Ocean Wang's avatar
Ocean Wang committed
68 69
    /// If the rrset has expired or doesn't exist in the cache,
    /// it will be added directly. It may be ingored if the new
70
    /// rrset is not more authoritative than the old rrset in cache.
Ocean Wang's avatar
Ocean Wang committed
71
    ///
72 73
    /// \param rrset The new rrset used to update cache.
    /// \param level trustworthiness of the rrset.
Ocean Wang's avatar
Ocean Wang committed
74
    /// \return return the rrset entry in the cache, it may be the
75
    /// new added rrset entry or existed one if it is not replaced.
76
    RRsetEntryPtr update(const isc::dns::AbstractRRset& rrset,
77
                         const RRsetTrustLevel& level);
78

79 80
    /// \short Protected memebers, so they can be accessed by tests.
protected:
81 82
    uint16_t class_; // The class of the rrset cache.
    isc::nsas::HashTable<RRsetEntry> rrset_table_;
83
    isc::util::LruList<RRsetEntry> rrset_lru_;
84
};
85 86

typedef boost::shared_ptr<RRsetCache> RRsetCachePtr;
Ocean Wang's avatar
Ocean Wang committed
87
typedef boost::shared_ptr<const RRsetCache> ConstRRsetCachePtr;
Ocean Wang's avatar
Ocean Wang committed
88

89 90 91 92 93
} // namespace cache
} // namespace isc

#endif // __RRSET_CACHE_H