I have the next custom type decorator for SQLAlchemy:
class TimeStamp(TypeDecorator):
impl = DateTime
cache_ok = True
LOCAL_TIMEZONE = datetime.utcnow().astimezone().tzinfo
def process_literal_param(self, value, dialect):
return self.imple.process_literal_param(value, dialect)
@property
def python_type(self):
return self.impl.python_type
def process_bind_param(self, value: datetime, dialect):
if value is None:
return None
if value.tzinfo is None:
value = value.astimezone(self.LOCAL_TIMEZONE)
return value.astimezone(timezone.utc)
def process_result_value(self, value, dialect):
if value is None:
return None
if value.tzinfo is None:
return value.replace(tzinfo=timezone.utc)
return value.astimezone(timezone.utc)
The problem is that SQLAlchemy asks me to setup the cache_ok flag... I've tried to read about this flag in docs but it's still not clear for me. I can't get how SQLAlchemy uses it.
What does it cache? Is my type decorator suitable for caching?