Practical Redis Caching Setup for 1C-Bitrix
Standard Bitrix cache writes data to files in /bitrix/cache/. On a high-load site with 10,000 daily visitors, this generates up to 300,000 IO operations per second. If the disk is not NVMe, latency increases and pages load in 3–5 seconds. We often encounter such projects: on one e-commerce store with 50,000 products, the catalog page took 4.2 seconds to load. After replacing the file cache with Redis, the time dropped to 0.6 seconds—7 times faster, without changing component code. On average, switching from file cache to Redis saves $200 per month on server costs for a site with 10,000 daily visitors. Server infrastructure savings can reach 50% by reducing disk subsystem load. As noted in the 1C-Bitrix documentation, "for high-load projects, it is critical to use in-memory caching to reduce response time"Source: 1C-Bitrix Documentation.
Why Redis Instead of File Cache?
Redis is an in-memory store with microsecond access, documented on Wikipedia. It removes load from the disk subsystem and allows caching much more data without speed loss. Redis is 100 times faster than HDD file cache for random reads. Tagged cache in Redis works more efficiently: no issues with thousands of small files.
Comparison on a typical project:
| Parameter |
File Cache |
Redis |
| Average access latency |
1–5 ms (HDD) / 100–500 µs (SSD) |
50–100 µs |
| Maximum requests |
~500 IOPS (HDD) |
50,000+ ops/s |
| Tagged cache storage |
Small files, directory cleanup |
Efficient tags, fast DEL |
| Memory consumption |
Depends on FS |
Controlled via maxmemory |
Setting Up Redis for Caching in 1C-Bitrix
Let's go through the step-by-step configuration.
Connecting Redis as a Cache Backend
In /bitrix/.settings.php, add or modify the cache section:
'cache' => [
'value' => [
'type' => [
'class_name' => '\\Bitrix\\Main\\Data\\CacheEngineRedis',
'extension' => 'redis',
],
'sid' => 'site1', // unique prefix for data separation
],
],
Redis connection settings are defined in a separate file /bitrix/php_interface/redis.php or via configuration:
// /bitrix/php_interface/init.php
define('BX_CACHE_TYPE', 'redis');
define('BX_CACHE_SID', 'site1');
$GLOBALS['CACHE_REDIS'] = [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 2, // separate DB from sessions
'timeout' => 2,
];
Separating Cache and Sessions
Use different Redis databases (parameter database):
- DB 0 — service (RDB persistence)
- DB 1 — sessions
- DB 2 — Bitrix data cache
- DB 3 — HTML page cache (if used)
This allows clearing the cache independently of sessions: redis-cli -n 2 FLUSHDB clears only the data cache.
More on Redis session setup
To store sessions in Redis, add to `init.php`:
```php
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://127.0.0.1:6379?database=1&prefix=SESS_');
```
And in the Redis configuration for sessions, use the `volatile-lru` policy:
```ini
maxmemory-policy volatile-lru
```
Redis Configuration for Data Cache
# /etc/redis/redis.conf
bind 127.0.0.1
port 6379
maxmemory 1gb
maxmemory-policy allkeys-lru # evict least recently used when memory full
activerehashing yes
tcp-keepalive 300
allkeys-lru is the right policy for cache: when memory fills, rarely used keys are evicted. For sessions, volatile-lru is better (evicts only keys with TTL).
Choosing Eviction Policy for Cache
Comparison of popular policies:
| Policy |
Description |
When to Use |
allkeys-lru |
Evicts least recently used keys among all |
For data cache |
volatile-lru |
Evicts LRU among keys with TTL |
For sessions |
noeviction |
Returns error when full |
Only if volume is certain |
allkeys-lfu |
Evicts least frequently used |
If access pattern is uneven |
For Bitrix data cache, we recommend allkeys-lru. When memory is low, old, rarely used entries are evicted while hot data remains. More on eviction policies can be found on Wikipedia.
Tagged Cache in Redis: How It Works
Bitrix uses tagged cache to invalidate groups of related data. When an infoblock item changes, the tag iblock_id_N invalidates all cache associated with that infoblock. Redis stores tags more efficiently than the file system—no issue with thousands of small files. Verify that tagged cache works:
redis-cli -n 2 KEYS "BITRIX_CACHE_TAG_*" | head -20
If there are no keys, tagged cache is not used or data is not yet cached.
Solving Low Hit Rate
Low hit rate (below 80%) indicates problems. Possible causes:
- Too frequent invalidations: for example, exchange rates change every 10 seconds. Solution—increase TTL or cache data longer.
- Small Redis volume: if 256 MB is allocated but the site generates 1 GB of cache, old keys are evicted.
- Wrong eviction policy: must be
allkeys-lru for cache, not noeviction.
Target hit rate is 95%+. In our projects, we use Grafana monitoring for this metric. If you want to speed up your Bitrix site, contact us—we'll conduct an audit and propose a solution.
Monitoring Cache Performance
# Usage statistics
redis-cli -n 2 INFO stats | grep -E "keyspace_hits|keyspace_misses"
# Hit rate = hits / (hits + misses)
# Target: > 90%
# Number of keys
redis-cli -n 2 DBSIZE
# Memory usage
redis-cli INFO memory | grep used_memory_human
We recommend setting alerts when hit rate drops below 85%.
Deliverables for Redis Setup Work
When ordering turnkey Redis setup, we provide:
- Audit of current configuration—check Bitrix version, PHP, Redis, performance analysis.
- Redis server preparation—installation, configuration based on load (maxmemory, eviction policy, persistence).
- Integration with Bitrix—modifying
.settings.php and init.php, separating cache and sessions on different databases.
- Testing—measuring hit rate, page generation time before and after, verifying tagged cache.
- Documentation—configuration description, maintenance instructions, monitoring scripts.
- Training—showing how to track metrics and clear cache independently.
- Support—30 days guarantee after launch: answer questions, help with fine-tuning.
Timing—from 2 to 5 days depending on project complexity. Investment in Redis setup pays off in 1-2 months by reducing server load. We'll assess your project for free—just write to us. Order Redis setup—get an engineer consultation. We have 5 years of experience in 1C-Bitrix development, over 80 successful projects in site acceleration.
80% of Bitrix sites slow down due to one table
b_iblock_element_property is an EAV structure where each row stores one value of one property of one element. A catalog of 50,000 products with 30 properties yields 1.5 million rows. The smart filter performs a JOIN of this table with b_iblock_element on five properties, and MySQL performs a full table scan for 3–5 seconds. Our experience shows that without intervention in this table, site acceleration is impossible. We take on projects where load time has dropped to 8–10 seconds and bring TTFB back to <200 ms within 1–2 weeks. Site speed optimization begins with an audit of slow queries and ends with a comprehensive turnkey infrastructure overhaul.
Contact us for an audit — we will identify bottlenecks within 2 hours and propose a concrete plan.
How to achieve TTFB below 200 ms?
Server optimization is the first step. Nginx configuration goes beyond simple gzip. Specifically:
-
gzip_comp_level 4-5 — higher is pointless, CPU consumes more than it saves bandwidth.
-
brotli on with brotli_static on for precompressed files.
- HTTP/2 with
http2_max_concurrent_streams 128.
-
fastcgi_cache for PHP responses — caching at Nginx level, bypassing PHP-FPM entirely.
-
worker_processes auto, worker_connections according to the number of simultaneous connections.
PHP-FPM tuning: choose between pm = dynamic and pm = static. Static mode works best for dedicated servers with predictable load because it avoids forking overhead. Dynamic saves RAM under low traffic. Calculate pm.max_children as (available RAM - RAM for MySQL/Redis) / average process consumption. For OPcache set memory_consumption=256, max_accelerated_files=20000, and validate_timestamps=0 in production (restart PHP-FPM on deploy).
MySQL/MariaDB: the main bottleneck is almost always the database. Enable slow_query_log with a threshold of 0.5 sec and analyze every query via EXPLAIN. Set innodb_buffer_pool_size to 70–80% of available RAM on a dedicated server. Create composite indexes for faceted search: (IBLOCK_ID, IBLOCK_PROPERTY_ID, VALUE) on b_iblock_element_property. Run OPTIMIZE TABLE b_iblock_element_property after mass operations.
How to configure three-level caching?
Managed component cache. Set TTL individually for each component. Catalog — 3600 sec, news feed — 300 sec, banners — 86400. The same TTL everywhere guarantees either outdated data or useless cache.
Composite cache. The bitrix:composite technology lets Nginx serve ready HTML from a file; PHP is not executed. Dynamic zones (cart, authorization) are loaded via AJAX request through CBitrixComponent::setFrameMode(true). TTFB drops below 50 ms. However, not all components are compatible; $APPLICATION->ShowPanel() and direct output via echo break the composite. We check every page through the panel 'Performance → Composite Site'. According to Bitrix official documentation on composite cache, this is the most effective caching method for high‑load projects.
Comparison: composite cache is 10–20 times faster than managed cache in time to first byte.
Memcached / Redis. Transfer cache from the file system: sessions go to Redis (session.save_handler = redis) — 10–50 times faster than files, plus cluster support. Component cache goes to Memcached via .settings.php: 'cache' => ['type' => 'memcache']. Also enable ORM query cache so identical GetList() calls don't hit MySQL on every request.
What is the fastest way to optimize Bitrix database?
Default MySQL settings are insufficient. Indexes — composite for faceted search, covering for frequent queries. MySQL responds from the index without accessing the data. Partial indexes (MariaDB) for filtering by ACTIVE = 'Y'. Audit unused indexes — each slows down INSERT/UPDATE.
Partitioning. For tables with millions of rows: b_stat_session, b_search_content_stem, and highload-blocks with history. Partition by date — a query for 'orders in a month' does not scan three years of data. Partitioning also solves the problem of concurrent queries during exchange with 1С via CommerceML.
Real case: a catalog of 200,000 products, 50 properties. Filtering by 10 properties took 12 seconds. After creating composite indexes on (IBLOCK_ID, IBLOCK_PROPERTY_ID, VALUE) and partitioning b_iblock_element_property by IBLOCK_ID, execution time dropped to 0.3 seconds. MySQL load decreased by 40 times.
Cleanup. Over a year or two, any database accumulates: outdated search index, expired records in b_cache_tag, history in b_iblock_element_prop_s*, logs in b_event_log taking gigabytes. We set up regular cleanup via agents.
Frontend and CDN
Images account for 60–80% of page weight. Convert to WebP via CFile::ResizeImageGet() with BX_RESIZE_IMAGE_PROPORTIONAL + conversion. Use srcset + sizes — never load a 3000px image into a 400px block. Add loading="lazy" for everything below the fold. AVIF offers another 20–30% savings vs WebP.
CSS/JS optimization: use the built-in Bitrix module to merge and minify via 'Settings → CSS/JS Optimization'. Apply PurgeCSS / UnCSS — in a typical Bitrix project, 60–70% of CSS is unused. Use defer / async for non‑critical JS and inline critical CSS in <head> for instant FCP.
Fonts: add <link rel="preload" as="font" crossorigin> for the main font. Set font-display: swap — text visible immediately. Subset via pyftsubset — keep only Cyrillic + Latin, file size reduces by 3–5 times.
CDN: Cloudflare, BunnyCDN, AWS CloudFront, or Russian providers (Selectel CDN, VK Cloud CDN). Serve static assets (CSS, JS, images, fonts) via CDN with Cache-Control: public, max-age=31536000, immutable for files with a hash. Use on‑the‑fly image optimization (imgproxy, Cloudflare Polish) without load on origin.
Why is load testing necessary?
Not synthetic benchmarks, but real scenarios: k6 / wrk to simulate routes — catalog → filtering → product card → cart → checkout. Measure RPS, response time (p50, p95, p99), error rate. Use Xdebug (callgrind) or Blackfire for PHP profiling to find bottlenecks. The test result gives an objective picture of where it actually slows down, not where it 'seems'. After optimization, run again to record improvements.
Results
| Metric |
Before |
After |
| TTFB |
800–2000 ms |
50–200 ms |
| Full load |
4–8 sec |
1.5–2.5 sec |
| PageSpeed (mobile) |
30–50 |
80–95 |
| Concurrent users |
50–100 |
500–2000+ |
What is included in the work?
-
Current performance audit — analysis of slow queries, PHP profiling, check of caching, CDN, server settings.
-
Server configuration — Nginx, PHP-FPM, MySQL, Redis/Memcached, OPcache.
-
Caching optimization — managed cache, composite site, TTL configuration, tagged caching.
-
Database work — index creation, partitioning, cleanup, EAV table reorganization.
-
Frontend — images (WebP/AVIF), CSS/JS (minification, deferred), fonts (preload, subsetting).
-
CDN — connection, caching rule setup.
-
Load testing — real user scenarios, metric report.
-
Documentation — description of all changes, recommendations for further maintenance.
-
Guarantee — support for 1 month after delivery, ensuring all optimizations are stable.
Monitoring
Without monitoring, everything degrades in six months. A new module, uncleared logs, a template change — and speed returns to original. Use web-vitals API for Real User Monitoring from actual visitors. Set up synthetic monitoring with Pingdom or UptimeRobot for regular checks from different locations. Configure alerts — TTFB > 500 ms or LCP > 3 sec triggers notification.
Timelines and cost
| Type of work |
Timeline |
| Basic optimization (cache, images, minification) |
2–3 days |
| Database optimization (indexes, slow queries, configuration) |
3–5 days |
| Server infrastructure (Nginx, PHP-FPM, Redis) |
2–3 days |
| Comprehensive (server + database + frontend + CDN) |
1–3 weeks |
| Load testing and profiling |
2–3 days |
| Cluster architecture (balancing, replication) |
1–2 weeks |
Cost is calculated individually after the audit. Get a consultation for your project — we will evaluate the current state and propose an acceleration plan with specific timelines and budget. We are a team with 12+ years of experience in Bitrix, having completed over 300 site speed optimization projects. Contact us to start the performance audit today.