示例#1
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int
ACE_Refcounted_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container,
                                                                                                             double purge_percent)
{
  // Check that the purge_percent is non-zero.
  if (purge_percent == 0)
    return 0;

  // Get the number of entries in the container which can be considered for purging.
  size_t const available_entries =
    container.current_size () - this->marked_as_closed_entries_;

  // Also whether the number of entries in the cache zero.
  // Oops! then there is no way out but exiting.
  if (available_entries <= 0)
    return 0;

  // Calculate the no of entries to remove from the cache depending
  // upon the <purge_percent>.
  size_t entries_to_remove
    = ACE_MAX (static_cast<size_t> (1),
               static_cast<size_t> (static_cast<double> (purge_percent)
                                    / 100 * available_entries));

  if (entries_to_remove >= available_entries  || entries_to_remove == 0)
    entries_to_remove = available_entries - 1;

  KEY *key_to_remove = 0;
  VALUE *value_to_remove = 0;

  for (size_t i = 0; i < entries_to_remove ; ++i)
    {
      this->minimum (container,
                     key_to_remove,
                     value_to_remove);

      // Simply verifying that the key is non-zero.
      // This is important for strategies where the minimum
      // entry cant be found due to constraints on the type of entry
      // to remove.
      if (key_to_remove == 0)
        return 0;

      if (this->cleanup_strategy_->cleanup (container,
                                            key_to_remove,
                                            value_to_remove) == -1)
        return -1;

      ++this->marked_as_closed_entries_;
    }

  return 0;
}
示例#2
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int
ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container,
                                                                                                  double purge_percent)
{
  // Check that the purge_percent is non-zero.
  if (purge_percent == 0)
    return 0;

  // Get the number of entries in the container.
  size_t current_map_size = container.current_size ();

  // Also whether the number of entries in the cache is just one!
  // Oops! then there is no way out but exiting. So return an error.
  //  if (current_map_size <= 1)
  if (current_map_size == 0)
    return 0;

  // Calculate the no of entries to remove from the cache depending
  // upon the <purge_percent>.
  size_t const entries_to_remove
    = ACE_MAX (static_cast<size_t> (1),
               static_cast<size_t> (static_cast<double> (purge_percent)
                                    / 100 * current_map_size));

  KEY *key_to_remove = 0;
  VALUE *value_to_remove = 0;

  for (size_t i = 0; i < entries_to_remove ; ++i)
    {
      this->minimum (container,
                     key_to_remove,
                     value_to_remove);

      // Simply verifying that the key is non-zero.
      // This is important for strategies where the minimum
      // entry cant be found due to constraints on the type of entry
      // to remove.
      if (key_to_remove == 0)
        return 0;

      if (this->cleanup_strategy_->cleanup (container,
                                            key_to_remove,
                                            value_to_remove) == -1)
        return -1;
    }

  return 0;
}
示例#3
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int
ACE_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container,
                                                                                       double purge_percent)
{
  // Check that the purge_percent is non-zero.
  if (ACE::is_equal (purge_percent, 0.0))
    return 0;

  // Get the number of entries in the container.
  size_t current_map_size = container.current_size ();

  // Also whether the number of entries in the cache is just one!
  // Oops! then there is no way out but exiting. So return an error.
  if (current_map_size == 0)
    return 0;

  // Calculate the no of entries to remove from the cache depending
  // upon the <purge_percent>.
  size_t entries_to_remove
    = ACE_MAX (static_cast<size_t> (1),
               static_cast<size_t> (static_cast<double> (purge_percent)
                                    / 100 * current_map_size));

  KEY *key_to_remove = 0;
  VALUE *value_to_remove = 0;

  for (size_t i = 0; i < entries_to_remove ; ++i)
    {
      this->minimum (container,
                     key_to_remove,
                     value_to_remove);

      if (this->cleanup_strategy_->cleanup (container,
                                            key_to_remove,
                                            value_to_remove) == -1)
        return -1;
    }

  return 0;
}