#include <Caching_Utility_T.h>
Public Types | |
| typedef ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY |
Public Member Functions | |
| ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *cleanup_strategy=0, int delete_cleanup_strategy=0) | |
| Constructor. | |
| ~ACE_Pair_Caching_Utility (void) | |
| Destructor. | |
| int | clear_cache (CONTAINER &container, double purge_percent) |
Protected Member Functions | |
| void | minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove) |
| Find the entry with minimum caching attributes. | |
| void | operator= (const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) |
| APUTIL (const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) | |
Protected Attributes | |
| CLEANUP_STRATEGY * | cleanup_strategy_ |
| int | delete_cleanup_strategy_ |
| Whether the cleanup_strategy should be destroyed or not. | |
This class defines the methods commonly used by the different caching strategies. For instance: method which decides and purges the entry from the container.
Definition at line 47 of file Caching_Utility_T.h.
|
|||||
|
Definition at line 51 of file Caching_Utility_T.h. |
|
||||||||||||||||
|
Constructor.
Definition at line 21 of file Caching_Utility_T.cpp. References ACE_NEW, and ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::delete_cleanup_strategy_.
00023 : cleanup_strategy_ (cleanup_strategy), 00024 delete_cleanup_strategy_ (delete_cleanup_strategy) 00025 { 00026 if (cleanup_strategy == 0) 00027 { 00028 ACE_NEW (this->cleanup_strategy_, 00029 CLEANUP_STRATEGY); 00030 this->delete_cleanup_strategy_ = 1; 00031 } 00032 } |
|
||||||||||
|
Destructor.
Definition at line 35 of file Caching_Utility_T.cpp. References ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::cleanup_strategy_, and ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::delete_cleanup_strategy_.
00036 {
00037 if (this->delete_cleanup_strategy_)
00038 delete this->cleanup_strategy_;
00039 }
|
|
||||||||||
|
|
|
||||||||||||||||
|
Purge entries from the . The Cleanup_Strategy will do the actual job of cleanup once the entries to be cleaned up are decided. Definition at line 42 of file Caching_Utility_T.cpp. References ACE_MAX, ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::cleanup_strategy_, and ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum().
00044 {
00045 // Check that the purge_percent is non-zero.
00046 if (purge_percent == 0)
00047 return 0;
00048
00049 // Get the number of entries in the container.
00050 size_t current_map_size = container.current_size ();
00051
00052 // Also whether the number of entries in the cache!
00053 // Oops! then there is no way out but exiting. So return an error.
00054 if (current_map_size == 0)
00055 return 0;
00056
00057 // Calculate the no of entries to remove from the cache depending
00058 // upon the <purge_percent>.
00059 size_t const entries_to_remove
00060 = ACE_MAX (static_cast<size_t> (1),
00061 static_cast<size_t> (static_cast<double> (purge_percent)
00062 / 100 * current_map_size));
00063 KEY *key_to_remove = 0;
00064 VALUE *value_to_remove = 0;
00065
00066 for (size_t i = 0; i < entries_to_remove ; ++i)
00067 {
00068 this->minimum (container,
00069 key_to_remove,
00070 value_to_remove);
00071
00072 // Simply verifying that the key is non-zero.
00073 // This is important for strategies where the minimum
00074 // entry cant be found due to constraints on the type of entry
00075 // to remove.
00076 if (key_to_remove == 0)
00077 return 0;
00078
00079 if (this->cleanup_strategy_->cleanup (container,
00080 key_to_remove,
00081 value_to_remove) == -1)
00082 return -1;
00083
00084 }
00085
00086 return 0;
00087 }
|
|
||||||||||||||||||||
|
Find the entry with minimum caching attributes.
Definition at line 90 of file Caching_Utility_T.cpp. Referenced by ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache().
00093 {
00094 // Starting values.
00095 ITERATOR iter = container.begin ();
00096 ITERATOR end = container.end ();
00097 ATTRIBUTES min = (*iter).int_id_.second ();
00098 key_to_remove = &(*iter).ext_id_;
00099 value_to_remove = &(*iter).int_id_;
00100
00101 // The iterator moves thru the container searching for the entry
00102 // with the lowest ATTRIBUTES.
00103 for (++iter;
00104 iter != end;
00105 ++iter)
00106 {
00107 if (min > (*iter).int_id_.second ())
00108 {
00109 // Ah! an item with lower ATTTRIBUTES...
00110 min = (*iter).int_id_.second ();
00111 key_to_remove = &(*iter).ext_id_;
00112 value_to_remove = &(*iter).int_id_;
00113 }
00114 }
00115 }
|
|
||||||||||
|
|
|
|||||
|
The cleanup strategy which can be used to destroy the entries of the container. Definition at line 76 of file Caching_Utility_T.h. Referenced by ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache(), and ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::~ACE_Pair_Caching_Utility(). |
|
|||||
|
Whether the cleanup_strategy should be destroyed or not.
Definition at line 79 of file Caching_Utility_T.h. Referenced by ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::ACE_Pair_Caching_Utility(), and ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::~ACE_Pair_Caching_Utility(). |
1.3.6