diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php
index 69d0cc7fcc76812b5142422a4e3930786f85c49c..badedb5d2ac88d215a9a4593483c54ab6e5ee6d1 100644
--- a/lib/Net/LDAP3.php
+++ b/lib/Net/LDAP3.php
@@ -2985,8 +2985,9 @@ class Net_LDAP3
     public function set_cache_data($key, $data, $ttl = 3600)
     {
         if ($cache = $this->get_cache()) {
-            if (!method_exists($cache, 'replace') || !$cache->replace($key, $data, MEMCACHE_COMPRESSED, $ttl)) {
-                return $cache->set($key, $data, MEMCACHE_COMPRESSED, $ttl);
+            $flags = defined('MEMCACHE_COMPRESSED') ? MEMCACHE_COMPRESSED : 0;
+            if (!method_exists($cache, 'replace') || !$cache->replace($key, $data, $flags, $ttl)) {
+                return $cache->set($key, $data, $flags, $ttl);
             }
             else {
                 return true;