Setting up Memcached for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Memcached Configuration for 1C-Bitrix

Memcached Configuration for 1C-Bitrix

1C-Bitrix has built-in Memcached support through its caching module. When properly configured, component cache, HTML page cache (composite site), and sessions are stored in memory, bypassing the filesystem. On a server with slow disks (HDD), the difference between file-based cache and Memcached is 5–10× in read time.

Installation and Basic Setup

apt install memcached php-memcached

# Configuration /etc/memcached.conf
-d                        # daemon mode
-m 1024                   # memory in MB
-u memcache
-l 127.0.0.1              # localhost only
-p 11211
-c 1024                   # max connections
-I 32m                    # max item size (for large cache objects)
-t 4                      # threads (= number of CPU cores)

-I 32m — the default per-item limit is 1 MB. 1C-Bitrix caches full HTML blocks of pages; a catalog page with 50 products in HTML can weigh 2–5 MB. Without increasing this limit, Memcached silently drops large objects without saving them.

Connecting Memcached to 1C-Bitrix

In the file /bitrix/.settings.php (not dbconn.php):

return [
    'cache' => [
        'value' => [
            'type' => 'memcache',
            'memcache' => [
                'host' => '127.0.0.1',
                'port' => '11211',
            ],
            'sid' => 'bitrix_cache',
        ],
    ],
];

Or via the admin interface: Settings → Product Settings → Caching — select "Memcache".

Session cache in php.ini:

session.save_handler = memcached
session.save_path = "127.0.0.1:11211"

Multiple Memcached Servers

With multiple application nodes, sessions must be stored in a shared Memcached:

// .settings.php with a server pool
'memcache' => [
    [
        'host' => '10.0.0.10',
        'port' => '11211',
        'weight' => 1,
    ],
    [
        'host' => '10.0.0.11',
        'port' => '11211',
        'weight' => 1,
    ],
],

Memcached uses consistent hashing to distribute keys across nodes — when a node is added or removed, only a portion of the keys are redistributed.

Monitoring and Diagnostics

# Basic statistics
echo "stats" | nc 127.0.0.1 11211

# Key metrics
echo "stats" | nc 127.0.0.1 11211 | grep -E "curr_items|bytes|get_hits|get_misses|evictions"

evictions > 0 — Memcached is evicting old data to make room for new entries. If evictions keep growing, increase -m or analyze what is consuming memory.

Hit rate = get_hits / (get_hits + get_misses). Below 80% — the cache is ineffective: TTL is too short or objects are being evicted prematurely.

# Calculate hit rate
hits=$(echo "stats" | nc 127.0.0.1 11211 | grep get_hits | awk '{print $3}')
misses=$(echo "stats" | nc 127.0.0.1 11211 | grep get_misses | awk '{print $3}')
echo "Hit rate: $(echo "scale=2; $hits / ($hits + $misses) * 100" | bc)%"

Memcached vs Redis for 1C-Bitrix

Criterion Memcached Redis
Performance Faster for simple get/set Comparable
Persistence None (data lost on restart) Yes (RDB/AOF)
Data structures Strings only Strings, lists, hashes, sets
Clustering No native cluster Redis Cluster
Bitrix support Native Via module or custom class

For component cache and HTML — Memcached is sufficient. For task queues, counters, pub/sub — use Redis.

Common Issue: Stale Cache After Updates

1C-Bitrix invalidates cache by tags. When a product is updated, all caches containing that product's tag are invalidated. If invalidation is not working, verify that the tag system is properly configured in cache_flags.php:

// bitrix/php_interface/cache_flags.php
$GLOBALS['CACHE_FLAGS'] = [
    'iblock_id_list' => true,
    'catalog_price' => true,
];