Index: trunk/xcache.c
===================================================================
--- trunk/xcache.c	(revision 857)
+++ trunk/xcache.c	(revision 858)
@@ -338,9 +338,11 @@
 					xc_entry_php_t *xce_php = (xc_entry_php_t *) xce;
 					fresh = p_php->file_mtime == xce_php->file_mtime && p_php->php->file_size == xce_php->php->file_size;
-					break;
 				}
+				break;
 
 			case XC_TYPE_VAR:
-				fresh = 1;
+				{
+					fresh = !VAR_ENTRY_EXPIRED(p);
+				}
 				break;
 
@@ -2688,5 +2690,4 @@
 	xc_entry_var_t xce, *stored_xce;
 	zval *name;
-	int found = 0;
 
 	if (!xc_var_caches) {
@@ -2702,25 +2703,15 @@
 
 	ENTER_LOCK(cache) {
-		stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC);
+		stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
 		if (stored_xce) {
-			if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) {
-				found = 1;
-				xc_processor_restore_zval(return_value, stored_xce->value, stored_xce->have_references TSRMLS_CC);
-				/* return */
-				break;
-			}
-			else {
-				xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
-			}
-		}
-
-		RETVAL_NULL();
+			/* return */
+			xc_processor_restore_zval(return_value, stored_xce->value, stored_xce->have_references TSRMLS_CC);
+			xc_cache_hit_dmz(cache TSRMLS_CC);
+		}
+		else {
+			RETVAL_NULL();
+			cache->misses ++;
+		}
 	} LEAVE_LOCK(cache);
-	if (found) {
-		xc_cache_hit_dmz(cache TSRMLS_CC);
-	}
-	else {
-		cache->misses ++;
-	}
 }
 /* }}} */
@@ -2771,5 +2762,4 @@
 	xc_entry_var_t xce, *stored_xce;
 	zval *name;
-	int found = 0;
 
 	if (!xc_var_caches) {
@@ -2787,23 +2777,13 @@
 		stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
 		if (stored_xce) {
-			if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) {
-				found = 1;
-				RETVAL_TRUE;
-				/* return */
-				break;
-			}
-			else {
-				xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
-			}
-		}
-
-		RETVAL_FALSE;
+			xc_cache_hit_dmz(cache TSRMLS_CC);
+			RETVAL_TRUE;
+			/* return */
+		}
+		else {
+			RETVAL_FALSE;
+		}
+
 	} LEAVE_LOCK(cache);
-	if (found) {
-		xc_cache_hit_dmz(cache TSRMLS_CC);
-	}
-	else {
-		cache->misses ++;
-	}
 }
 /* }}} */
@@ -2902,36 +2882,27 @@
 
 	ENTER_LOCK(cache) {
-		stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC);
+		stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC);
 		if (stored_xce) {
 			TRACE("incdec: gotxce %s", xce.entry.name.str.val);
-			/* timeout */
-			if (VAR_ENTRY_EXPIRED(&(stored_xce->entry))) {
-				TRACE("%s", "incdec: expired");
-				xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
-				stored_xce = NULL;
-			}
-			else {
-				/* do it in place */
-				if (Z_TYPE_P(stored_xce->value) == IS_LONG) {
-					zval *zv;
-					stored_xce->entry.ctime = XG(request_time);
-					stored_xce->entry.ttl   = xce.entry.ttl;
-					TRACE("%s", "incdec: islong");
-					value = Z_LVAL_P(stored_xce->value);
-					value += (inc == 1 ? count : - count);
-					RETVAL_LONG(value);
-
-					zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_xce->value);
-					Z_LVAL_P(zv) = value;
-					break; /* leave lock */
-				}
-				else {
-					TRACE("%s", "incdec: notlong");
-					xc_processor_restore_zval(&oldzval, stored_xce->value, stored_xce->have_references TSRMLS_CC);
-					convert_to_long(&oldzval);
-					value = Z_LVAL(oldzval);
-					zval_dtor(&oldzval);
-				}
-			}
+			/* do it in place */
+			if (Z_TYPE_P(stored_xce->value) == IS_LONG) {
+				zval *zv;
+				stored_xce->entry.ctime = XG(request_time);
+				stored_xce->entry.ttl   = xce.entry.ttl;
+				TRACE("%s", "incdec: islong");
+				value = Z_LVAL_P(stored_xce->value);
+				value += (inc == 1 ? count : - count);
+				RETVAL_LONG(value);
+
+				zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_xce->value);
+				Z_LVAL_P(zv) = value;
+				break; /* leave lock */
+			}
+
+			TRACE("%s", "incdec: notlong");
+			xc_processor_restore_zval(&oldzval, stored_xce->value, stored_xce->have_references TSRMLS_CC);
+			convert_to_long(&oldzval);
+			value = Z_LVAL(oldzval);
+			zval_dtor(&oldzval);
 		}
 		else {
@@ -2941,5 +2912,5 @@
 		value += (inc == 1 ? count : - count);
 		RETVAL_LONG(value);
-		stored_xce->value = return_value;
+		xce.value = return_value;
 
 		if (stored_xce) {
