--- mod_mem_cache.1.99.c	Thu Dec 11 15:36:06 2003
+++ mod_mem_cache.1.100.c	Thu Dec 11 16:50:40 2003
@@ -1028,6 +1028,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;
                 }
@@ -1043,7 +1044,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);
