HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/share/doc/python-sqlalchemy-0.9.8/examples/dogpile_caching/helloworld.py
"""helloworld.py

Illustrate how to load some data, and cache the results.

"""

from .environment import Session
from .model import Person
from .caching_query import FromCache

# load Person objects.  cache the result in the "default" cache region
print("loading people....")
people = Session.query(Person).options(FromCache("default")).all()

# remove the Session.  next query starts from scratch.
Session.remove()

# load again, using the same FromCache option. now they're cached,
# so no SQL is emitted.
print("loading people....again!")
people = Session.query(Person).options(FromCache("default")).all()

# Specifying a different query produces a different cache key, so
# these results are independently cached.
print("loading people two through twelve")
people_two_through_twelve = Session.query(Person).\
                            options(FromCache("default")).\
                            filter(Person.name.between("person 02", "person 12")).\
                            all()

# the data is cached under string structure of the SQL statement, *plus*
# the bind parameters of the query.    So this query, having
# different literal parameters under "Person.name.between()" than the
# previous one, issues new SQL...
print("loading people five through fifteen")
people_five_through_fifteen = Session.query(Person).\
                            options(FromCache("default")).\
                            filter(Person.name.between("person 05", "person 15")).\
                            all()


# ... but using the same params as are already cached, no SQL
print("loading people two through twelve...again!")
people_two_through_twelve = Session.query(Person).\
                            options(FromCache("default")).\
                            filter(Person.name.between("person 02", "person 12")).\
                            all()


# invalidate the cache for the three queries we've done.  Recreate
# each Query, which includes at the very least the same FromCache,
# same list of objects to be loaded, and the same parameters in the
# same order, then call invalidate().
print("invalidating everything")
Session.query(Person).options(FromCache("default")).invalidate()
Session.query(Person).\
            options(FromCache("default")).\
            filter(Person.name.between("person 02", "person 12")).invalidate()
Session.query(Person).\
            options(FromCache("default", "people_on_range")).\
            filter(Person.name.between("person 05", "person 15")).invalidate()