-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
81 lines (68 loc) · 2.73 KB
/
config.py
File metadata and controls
81 lines (68 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
from cache import CacheManager, InMemoryCache, RedisCache
class Config:
"""Application configuration with cache settings"""
SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-change-in-production'
UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER') or 'uploads'
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB
# Cache Configuration
CACHE_TYPE = os.environ.get('CACHE_TYPE', 'redis') # memory, file, redis
CACHE_DEFAULT_TTL = int(os.environ.get('CACHE_DEFAULT_TTL', '1800')) # 30 minutes
CACHE_MAX_SIZE = int(os.environ.get('CACHE_MAX_SIZE', '1000'))
# Redis settings (if using Redis cache)
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379'))
REDIS_DB = int(os.environ.get('REDIS_DB', '0'))
REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD')
# File cache settings
CACHE_DIR = os.environ.get('CACHE_DIR', 'cache_data')
# API Configuration
API_TIMEOUTS = {
'default': 10,
'gipod': 10,
'ndw': 15,
'astra': 12,
'streetmanager': 8
}
# Cache TTL per adapter (in seconds)
ADAPTER_CACHE_TTL = {
'BE': 1800, # GIPOD - 30 minutes
'NL': 3600, # NDW - 1 hour
'CH': 2400, # ASTRA - 40 minutes
'UK': 1200, # Street Manager - 20 minutes
}
# Route analysis settings
ROUTE_BUFFER_KM = 0.5
WORK_DISTANCE_THRESHOLD_KM = 0.5
MAX_DETOURS = 3
# Map settings
DEFAULT_ZOOM = 12
ROUTE_COLOR = 'blue'
WORK_MARKER_COLOR = 'red'
DETOUR_COLOR = 'green'
@staticmethod
def get_cache_manager():
"""Factory method to create appropriate cache manager"""
cache_type = Config.CACHE_TYPE.lower()
if cache_type == 'redis':
try:
strategy = RedisCache(
host=Config.REDIS_HOST,
port=Config.REDIS_PORT,
db=Config.REDIS_DB,
password=Config.REDIS_PASSWORD
)
print("✅ Using Redis cache")
except Exception as e:
print(f"❌ Redis cache failed, falling back to memory: {e}")
strategy = InMemoryCache(max_size=Config.CACHE_MAX_SIZE)
elif cache_type == 'file':
strategy = FileCache(
cache_dir=Config.CACHE_DIR,
max_files=Config.CACHE_MAX_SIZE
)
print("✅ Using file-based cache")
else: # memory (default)
strategy = InMemoryCache(max_size=Config.CACHE_MAX_SIZE)
print("✅ Using in-memory cache")
return CacheManager(strategy, default_ttl=Config.CACHE_DEFAULT_TTL)