On Wed, May 26, 2021, at 3:07 AM, niuji...@gmail.com 
<mailto:niuji...%40gmail.com> wrote:
> I have consistently receiving the warning: 
> will not produce a cache key because the ``cache_ok`` flag is not set to 
> True.  Set this flag to True if this type object's state is safe to use in a 
> cache key, or False to disable this warning.
> 
> 
> After reading the documentation, I learned that the "cache_ok" class-level 
> attribute can be set to either True or False. But the documentation is very 
> abstract on when to use it? What is cache key? Is it for loading and caching 
> a set of objects from the database? Or caching the query itself?

the caching system is used to cache the generated SQL and related parameter and 
result-handling structures for a statement object and is described at:

https://docs.sqlalchemy.org/en/14/core/connections.html#sql-compilation-caching

it is always safe to set cache_ok=False on your TypeDecorator class,  you will 
however lose the benefit of SQL statement caching for statements which include 
use of this datatype.


> 
> If my TypeDecorator class doesn't even have a __init__method, just 
> "process_bind_param" and "process_result_value" two methods, do I even need 
> to bother with this "cache_ok" setting at all?

If your TypeDecorator is stateless, then it's fine to set cache_ok=True.


> 

> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/abe578f0-fd11-468f-857d-dee6fd77ebc5n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/abe578f0-fd11-468f-857d-dee6fd77ebc5n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f3640072-8d16-4f59-bc67-f468c78878cb%40www.fastmail.com.

Reply via email to