-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.sql
More file actions
58 lines (51 loc) · 1.54 KB
/
cache.sql
File metadata and controls
58 lines (51 loc) · 1.54 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
-- make sure subsequent calls actually are from the cache.
-- the next check is not complete without this.
CREATE OR REPLACE FUNCTION check_for_func_persists() RETURNS text LANGUAGE python AS
$python$
import Postgres
if not hasattr(Postgres, 'CACHED'):
Postgres.CACHED = __func__
Postgres.CACHEDD = globals()
def main():
assert Postgres.CACHED is __func__
assert Postgres.CACHEDD is globals()
return 'success'
$python$;
SELECT check_for_func_persists();
SELECT check_for_func_persists();
-- can't use proc() for the func cache check as the function cache
-- is sys.modules, which proc()/Postgres.Function doesn't use.
CREATE OR REPLACE FUNCTION check_for_func_cache_clear() RETURNS text LANGUAGE python AS
$python$
import Postgres
foo = 'init'
def main():
global foo
assert foo == 'init'
foo = 'override'
Postgres.clearcache()
# it did change, but the next time this
# function is called, it will be a new module.
assert globals()['foo'] == 'override'
return 'success'
$python$;
SELECT check_for_func_cache_clear();
-- the first one is the setup
SELECT check_for_func_cache_clear();
DROP TYPE IF EXISTS cached_or_not;
CREATE TYPE cached_or_not AS (i int, t text);
CREATE OR REPLACE FUNCTION check_for_type_cache() RETURNS text LANGUAGE python AS
$python$
from Postgres.types import regtype
import Postgres
oid = regtype('cached_or_not')
T = Postgres.Type(oid)
def main():
cur = Postgres.Type(oid)
assert cur is T
Postgres.clearcache()
newtyp = Postgres.Type(oid)
assert cur is not newtyp
return 'success'
$python$;
SELECT check_for_type_cache();