diff options
Diffstat (limited to 'ace/Caching_Strategies_T.h')
-rw-r--r-- | ace/Caching_Strategies_T.h | 208 |
1 files changed, 50 insertions, 158 deletions
diff --git a/ace/Caching_Strategies_T.h b/ace/Caching_Strategies_T.h index 8e7db943ba7..686c5331d9e 100644 --- a/ace/Caching_Strategies_T.h +++ b/ace/Caching_Strategies_T.h @@ -27,7 +27,7 @@ #include "ace/Cleanup_Strategies_T.h" -template <class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template <class CONTAINER> class ACE_LRU_Caching_Strategy { // = TITLE @@ -39,28 +39,17 @@ class ACE_LRU_Caching_Strategy // is updated whenever an item is inserted or looked up in the // container. When the need of purging entries arises, the items // with the lowest timer values are removed. - // - // Explanation of the template parameter list: - // CONTAINER is any map with entries of type <KEY, VALUE>. - // The ATTRIBUTES are the deciding factor for purging of entries - // and should logically be included with the VALUE. Some ways of - // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the - // class which can be plugged in and which decides the entries - // to purge. public: // Traits. - typedef ATTRIBUTES CACHING_ATTRIBUTES; + typedef int ATTRIBUTES; typedef CONTAINER CACHE; // = Initialisation and termination. - ACE_LRU_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + ACE_LRU_Caching_Strategy (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // The <container> is the map in which the entries reside. // The Cleanup_Strategy is the callback class to which the entries // to be cleaned up will be delegated. The <delete_cleanup_strategy> @@ -68,29 +57,23 @@ public: // Also, the timer attribute is initialed to zero in this constructor. // And the <purge_percent> field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%. The ultility which helps the caching strategy in the - // purging of entries needs to be specified. By default a new one - // will be created of type CACHING_STRATEGY_UTILITY and - // <delete_caching_strategy_utility> decides whether to destroy the - // utility object or not. + // set to 10%. ~ACE_LRU_Caching_Strategy (void); // = Operations of the strategy. - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + int open (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // This method which does the actual initialisation. ATTRIBUTES attributes (void); // Accessor method for the timer attributes. // = Accessor methods for the percentage of entries to purge. - unsigned int purge_percent (void); + int purge_percent (void); - void purge_percent (unsigned int percentage); + void purge_percent (int percentage); // = Strategy related Operations @@ -124,20 +107,12 @@ public: // This is the method which looks at each ITEM's attributes and // then decides on the one to remove. - int clear_cache (CONTAINER &container, - unsigned int &total_container_entries); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. The <total_container_entries> - // can be specified explicitly and facilitates use of the caching - // strategy even when the <entries_> is not maintained by the - // strategy itself. - void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; + typedef ACE_Default_Cleanup_Strategy<CONTAINER> CLEANUP_STRATEGY; ATTRIBUTES timer_; // This element is the one which is the deciding factor for purging @@ -149,7 +124,7 @@ private: unsigned int entries_; // The no of entries bound in the cache. - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy_; + ACE_Cleanup_Strategy<CONTAINER> *cleanup_strategy_; // The cleanup strategy which can be used to destroy the entries of // the container. @@ -157,20 +132,15 @@ private: // The flag which denotes the ownership of the cleanup strategy. // If 1 then this class itself will destroy the strategy. - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + ACE_Caching_Strategy_Utility<CONTAINER, ATTRIBUTES> caching_strategy_utility_; // This is the helper class which will decide and expunge entries // from the cache. - - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. }; ////////////////////////////////////////////////////////////////////////// -template <class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template <class CONTAINER> class ACE_LFU_Caching_Strategy { // = TITLE @@ -182,28 +152,15 @@ class ACE_LFU_Caching_Strategy // the item is bound or looked up in the cache. Thus it denotes // the frequency of use. According to the value of the attribute // the item is removed from the CONTAINER i.e cache. - // - // Explanation of the template parameter list: - // CONTAINER is any map with entries of type <KEY, VALUE>. - // The ATTRIBUTES are the deciding factor for purging of entries - // and should logically be included with the VALUE. Some ways of - // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the - // class which can be plugged in and which decides the entries - // to purge. - public: // Traits. - typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; + typedef int ATTRIBUTES; // = Initialisation and termination methods. - ACE_LFU_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + ACE_LFU_Caching_Strategy (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // The <container> is the map in which the entries reside. // The Cleanup_Strategy is the callback class to which the entries // to be cleaned up will be delegated. The <delete_cleanup_strategy> @@ -211,18 +168,12 @@ public: // Also, the timer attribute is initialed to zero in this constructor. // And the <purge_percent> field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%.The ultility which helps the caching strategy in the - // purging of entries will be default be the - // ACE_Caching_Strategy_Utility and the - // <delete_caching_strategy_utility> decides whether to destroy the - // utility or not. + // set to 10%. ~ACE_LFU_Caching_Strategy (void); - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + int open (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // This method which does the actual initialisation. // = Strategy methods. @@ -231,9 +182,9 @@ public: // Access the attributes. // = Accessor methods for the percentage of entries to purge. - unsigned int purge_percent (void); + int purge_percent (void); - void purge_percent (unsigned int percentage); + void purge_percent (int percentage); // = Strategy related Operations @@ -266,28 +217,20 @@ public: // This is the method which looks at each ITEM's attributes and // then decides on the one to remove. - int clear_cache (CONTAINER &container, - unsigned int &total_container_entries); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. The <total_container_entries> - // can be specified explicitly and facilitates use of the caching - // strategy even when the <entries_> is not maintained by the - // strategy itself. - void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; - + typedef ACE_Default_Cleanup_Strategy<CONTAINER> CLEANUP_STRATEGY; + unsigned int purge_percent_; // The level about which the purging will happen automagically. unsigned int entries_; // The no of entries bound in the cache. - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy_; + ACE_Cleanup_Strategy<CONTAINER> *cleanup_strategy_; // The cleanup strategy which can be used to destroy the entries of // the container. @@ -295,49 +238,32 @@ private: // The flag which denotes the ownership of the cleanup strategy. // If 1 then this class itself will destroy the strategy. - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + ACE_Caching_Strategy_Utility<CONTAINER, ATTRIBUTES> caching_strategy_utility_; // This is the helper class which will decide and expunge entries // from the cache. - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. }; ///////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template<class CONTAINER> class ACE_FIFO_Caching_Strategy { // = TITLE - // The First In First Out strategy is implemented wherein each - // item is ordered. + // The First In First Out strategy is implemented wherein each + // item is ordered. // // = DESCRIPTION - // The order tag of each item is used to decide the item to be - // removed from the cache. The items with least order are removed. - // - // Explanation of the template parameter list: - // CONTAINER is any map with entries of type <KEY, VALUE>. - // The ATTRIBUTES are the deciding factor for purging of entries - // and should logically be included with the VALUE. Some ways of - // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the - // class which can be plugged in and which decides the entries - // to purge. - + // The order tag of each item is used to decide the item to be + // removed from the cache. The items with least order are removed. public: - typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; + typedef int ATTRIBUTES; // = Initialisation and termination. - ACE_FIFO_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + ACE_FIFO_Caching_Strategy (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // The <container> is the map in which the entries reside. // The Cleanup_Strategy is the callback class to which the entries // to be cleaned up will be delegated. The <delete_cleanup_strategy> @@ -345,18 +271,12 @@ public: // Also, the timer attribute is initialed to zero in this constructor. // And the <purge_percent> field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%.The ultility which helps the caching strategy in the - // purging of entries will be default be the - // ACE_Caching_Strategy_Utility and the - // <delete_caching_strategy_utility> decides whether to destroy the - // utility or not. + // set to 10%. ~ACE_FIFO_Caching_Strategy (void); - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + int open (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // This method which does the actual initialisation. // = Strategy methods. @@ -365,9 +285,9 @@ public: // Accessor method. // = Accessor methods for the percentage of entries to purge. - unsigned int purge_percent (void); + int purge_percent (void); - void purge_percent (unsigned int percentage); + void purge_percent (int percentage); // = Strategy related Operations @@ -398,21 +318,13 @@ public: // This is the method which looks at each ITEM's attributes and // then decides on the one to remove. - int clear_cache (CONTAINER &container, - unsigned int &total_container_entries); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. The <total_container_entries> - // can be specified explicitly and facilitates use of the caching - // strategy even when the <entries_> is not maintained by the - // strategy itself. - void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; - + typedef ACE_Default_Cleanup_Strategy<CONTAINER> CLEANUP_STRATEGY; + ATTRIBUTES order_; // The order is the deciding factor for the item to be removed from // the cache. @@ -423,7 +335,7 @@ private: unsigned int entries_; // The no of entries bound in the cache. - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy_; + ACE_Cleanup_Strategy<CONTAINER> *cleanup_strategy_; // The cleanup strategy which can be used to destroy the entries of // the container. @@ -431,18 +343,12 @@ private: // The flag which denotes the ownership of the cleanup strategy. // If 1 then this class itself will destroy the strategy. - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + ACE_Caching_Strategy_Utility<CONTAINER, ATTRIBUTES> caching_strategy_utility_; // This is the helper class which will decide and expunge entries // from the cache. - - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. - }; -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template<class CONTAINER> class ACE_Null_Caching_Strategy { // = TITLE @@ -455,24 +361,18 @@ class ACE_Null_Caching_Strategy public: - // = Traits. - typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; + typedef int ATTRIBUTES; // = Initialisation and termination. - ACE_Null_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + ACE_Null_Caching_Strategy (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); ~ACE_Null_Caching_Strategy (void); - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); + int open (ACE_Cleanup_Strategy<CONTAINER> *cleanup_s = 0, + int delete_cleanup_strategy = 1); // This method which does the actual initialisation. // = Strategy methods. All are NO_OP methods!!! @@ -481,9 +381,9 @@ public: // Accessor method. // = Accessor methods for the percentage of entries to purge. - unsigned int purge_percent (void); + int purge_percent (void); - void purge_percent (unsigned int percentage); + void purge_percent (int percentage); // = Strategy related Operations @@ -514,14 +414,6 @@ public: // This is the method which looks at each ITEM's attributes and // then decides on the one to remove. - int clear_cache (CONTAINER &container, - unsigned int &total_container_entries); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. The <total_container_entries> - // can be specified explicitly and facilitates use of the caching - // strategy even when the <entries_> is not maintained by the - // strategy itself. - void dump (void) const; // Dumps the state of the object. |