rrset_cache.h 3.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// 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.

// $Id$

#ifndef __RRSET_CACHE_H
#define __RRSET_CACHE_H

20
#include <cache/rrset_entry.h>
21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <nsas/hash_table.h>
#include <nsas/lru_list.h>

using namespace isc::nsas;

namespace isc {
namespace cache {

class RRsetEntry;

/// \brief RRset Cache
/// The object of RRsetCache represented the cache for class-specific
/// RRsets.
class RRsetCache{
35 36 37 38 39 40 41 42 43
    ///
    /// \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&);
44
public:
45 46
    /// \brief Constructor
    ///
47 48 49
    /// \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);
50 51
    ~RRsetCache() {}
    //@}
Ocean Wang's avatar
Ocean Wang committed
52

53
    /// \brief Look up rrset in cache.
54 55 56 57
    ///
    /// \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
58 59 60
    /// found in the cache, or else, return NULL.
    RRsetEntryPtr lookup(const isc::dns::Name& qname,
                         const isc::dns::RRType& qtype);
61

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

    /// \brief Dump the rrset cache to specified file.
76 77 78
    ///
    /// \param file_name The file to write to
    ///
79 80 81 82
    /// \todo It should can be dumped to one configured database.
    void dump(const std::string& file_name);

    /// \brief Load the cache from one file.
83 84 85
    ///
    /// \param file_name The file to read from
    ///
86 87 88
    /// \todo It should can be loaded from one configured database.
    void load(const std::string& file_name);

Ocean Wang's avatar
Ocean Wang committed
89
    /// \brief Resize the size of rrset cache in runtime.
90 91 92
    ///
    /// \param The size to resize to
    /// \return true
93 94 95 96 97 98 99
    bool resize(uint32_t size);

private:
    uint16_t class_; // The class of the rrset cache.
    isc::nsas::HashTable<RRsetEntry> rrset_table_;
    isc::nsas::LruList<RRsetEntry> rrset_lru_;
};
100 101

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

104 105 106 107 108
} // namespace cache
} // namespace isc

#endif // __RRSET_CACHE_H