diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2013-08-17 12:32:07 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2013-08-17 12:32:07 +0200 |
commit | 8a3f0f51b2406e6ee9537fdc96cadc0d3fa2194c (patch) | |
tree | 49608eb4f63bbe85ff8c730b90828430f4cf9567 /pynslcd/protocol.py | |
parent | 84d22e608b03c154d11e54ff34d7b87bf1d78cfa (diff) | |
parent | a066bcb17e1b99a42a5834d1ace6feba7c9b60b7 (diff) |
Improvements to pynslcd caching functionality
This fixes most of the existing caching functionality. Cache expiry,
negative hits and entries going away remain to be implemented.
Diffstat (limited to 'pynslcd/protocol.py')
-rw-r--r-- | pynslcd/protocol.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/pynslcd/protocol.py b/pynslcd/protocol.py index cafda9d..1472c04 100644 --- a/pynslcd/protocol.py +++ b/pynslcd/protocol.py @@ -37,10 +37,41 @@ class Search(search.LDAPSearch): class Cache(cache.Cache): - def retrieve(self, parameters): - query = cache.CnAliasedQuery('protocol', parameters) - for row in cache.RowGrouper(query.execute(self.con), ('cn', ), ('alias', )): - yield row['cn'], row['alias'], row['ipProtocolNumber'] + tables = ('protocol_cache', 'protocol_alias_cache') + + create_sql = ''' + CREATE TABLE IF NOT EXISTS `protocol_cache` + ( `cn` TEXT PRIMARY KEY, + `ipProtocolNumber` INTEGER NOT NULL, + `mtime` TIMESTAMP NOT NULL ); + CREATE TABLE IF NOT EXISTS `protocol_alias_cache` + ( `protocol` TEXT NOT NULL, + `cn` TEXT NOT NULL, + FOREIGN KEY(`protocol`) REFERENCES `protocol_cache`(`cn`) + ON DELETE CASCADE ON UPDATE CASCADE ); + CREATE INDEX IF NOT EXISTS `protocol_alias_idx` ON `protocol_alias_cache`(`protocol`); + ''' + + retrieve_sql = ''' + SELECT `protocol_cache`.`cn` AS `cn`, `protocol_alias_cache`.`cn` AS `alias`, + `ipProtocolNumber`, `mtime` + FROM `protocol_cache` + LEFT JOIN `protocol_alias_cache` + ON `protocol_alias_cache`.`protocol` = `protocol_cache`.`cn` + ''' + + retrieve_by = dict( + cn=''' + ( `protocol_cache`.`cn` = ? OR + `protocol_cache`.`cn` IN ( + SELECT `by_alias`.`protocol` + FROM `protocol_alias_cache` `by_alias` + WHERE `by_alias`.`cn` = ?)) + ''', + ) + + group_by = (0, ) # cn + group_columns = (1, ) # alias class ProtocolRequest(common.Request): |