architect/_archive/2025-11-26-cleanup/cifra/11_DATA_MANAGEMENT.md

CIFRA — Управление данными

Версия: 2.0.0
Дата: 2025-11-10


Caching Strategy (3 уровня)

L1: Request Cache (In-Memory)    0.1ms
L2: Redis (Application)          1-5ms
L3: Database                     10-50ms

TTL стратегия

CACHE_TTL = {
    'User': 300,        # 5 min
    'Contact': 600,     # 10 min
    'Product': 3600,    # 1 hour
    'Category': 86400,  # 24 hours
}

Caching decorator

from cifra.cache import cached

@cached(ttl=600, key_prefix="contact")
async def get_contact(db, contact_id):
    return await db.query(Contact).get(contact_id)

File Upload

Chunked upload (для файлов > 10MB)

# 1. Initialize
upload_id = await upload_manager.init(
    filename='large_file.zip',
    total_size=100_000_000  # 100MB
)

# 2. Upload chunks
for chunk in file_chunks:
    await upload_manager.upload_chunk(upload_id, chunk)

# 3. Finalize
file_record = await upload_manager.finalize(upload_id)

Storage backends

file_upload:
  storage:
    backend: s3  # local, s3, azure
    s3:
      bucket: my-bucket
      region: us-east-1

Image processing

from cifra.media import ImageProcessor

# Create thumbnails
thumbnails = await processor.create_thumbnails(
    file=image,
    sizes={
        'small': (150, 150),
        'medium': (300, 300),
        'large': (800, 800)
    }
)

Report Builder

report:
  id: sales_by_month
  name: "Monthly Sales Report"

  query:
    entity: Sale
    aggregations:
      - field: amount
        operation: sum
    group_by:
      - field: "DATE_TRUNC('month', created_at)"

  outputs:
    - type: pdf
    - type: excel
    - type: csv

Generate report

from cifra.reports import ReportBuilder

report = await builder.generate(
    report_id='sales_by_month',
    parameters={
        'start_date': '2025-01-01',
        'end_date': '2025-12-31'
    },
    format='pdf'
)

Backup & Restore

# Backup database
cifra db backup --output backup_$(date +%Y%m%d).sql

# Restore
cifra db restore backup_20251110.sql

Import/Export

# Export to CSV
cifra export Contact --format csv --output contacts.csv

# Import from CSV
cifra import contacts.csv --entity Contact

Следующий документ: DEVELOPER_GUIDE.md →