# -*- coding: utf-8 -*-

"""Database, caching and logging configuration settings."""


# Database backend settings
DATABASES = {
    'default': {
        'ENGINE': 'transaction_hooks.backends.sqlite3',
        'NAME': working_path('dbs/pootle.db'),
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
        'ATOMIC_REQUESTS': True,
    }
}


# Cache Backend settings
#
# By default we use Redis as our main cache backend as we potentially rely on
# features specific to Redis.  Other backends will likely not work.
#
# For more information, check
# http://docs.djangoproject.com/en/dev/topics/cache/#setting-up-the-cache
# and http://niwibe.github.io/django-redis/
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'TIMEOUT': 60,
    },
    'redis': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/2',
        'TIMEOUT': None,
    },
    'stats': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/3',
        'TIMEOUT': None,
    },
    'exports': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': working_path('exports/'),
        'TIMEOUT': 259200,  # 3 days.
    },
}


# Using caching to store sessions improves performance for anonymous
# users. For more info, check
# http://docs.djangoproject.com/en/dev/topics/http/sessions/#configuring-the-session-engine
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'

# To improve performance, non-logged users get cached copies of most pages.
# This variable is the number of seconds for which a page will be reused from
# cache. If you have a small server where more real-time statistics is
# important, you can make this lower.
CACHE_MIDDLEWARE_SECONDS = 600

# Pootle caches certain items such as template fragments, permissions, language
# and project names etc. These are kept in memory for the duration in seconds
# defined here.
POOTLE_CACHE_TIMEOUT = 604800


#
# Redis Queue
#

RQ_QUEUES = {
    'default': {
        'USE_REDIS_CACHE': 'redis',
        'DEFAULT_TIMEOUT': 360,
    },
}
