--- mod_mem_cache.1.100.c	Fri Dec 12 15:10:33 2003
+++ mod_mem_cache.c	Fri Dec 12 15:30:08 2003
@@ -1013,6 +1013,7 @@
                  * correct size and copy the streamed response into that 
                  * buffer */
                 char *buf = malloc(obj->count);
+                cache_object_t *tmp_obj = NULL;
                 if (!buf) {
                     return APR_ENOMEM;
                 }
@@ -1028,7 +1029,18 @@
                 if (sconf->lock) {
                     apr_thread_mutex_lock(sconf->lock);
                 }
-                cache_remove(sconf->cache_cache, obj);
+                /* We need to check if the object has been removed/replaced 
+                 * from/in the cache, this could happen in some cases, because 
+                 * the current request is a streaming response that is handled 
+                 * in multiple individual pieces. - fixing Bugzilla Defect 21285
+                 */
+                if((tmp_obj = (cache_object_t *) cache_find(sconf->cache_cache, obj->key)) &&
+                    (tmp_obj == obj)) {
+                    cache_remove(sconf->cache_cache, obj);
+                }
+                else {
+                    obj->cleanup = 0;
+                }
                 mobj->m_len = obj->count;
                 cache_insert(sconf->cache_cache, obj);                
                 sconf->cache_size -= (mobj->m_len - obj->count);
