alex / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.
BSD 3-Clause "New" or "Revised" License
381 stars 60 forks source link

add cache_dir #41

Open sn6uv opened 9 years ago

sn6uv commented 9 years ago

New Cache API

alex commented 9 years ago

I'd kind of prefer to come up with a better API, e.g. cache=DirectoryCache("path"), with the default being DirectoryCache(tmpdir), that way someone can write the AppEngine cache or whatever else they asked for in another issue.

sn6uv commented 9 years ago

Working with the App engine #24 should be relatively simple. Something like the following (totally untested) code should work:

class AppEngineCache(object):
    VERSION=1
    def __init__(self, cache_id):
        self.cache_id = cache_id

    def _get_key(self, grammar_hash):
        return "rply-%s-%s-%s" % (self.VERSION, self.cache_id, grammar_hash)

    def load(self, grammar_hash):
        cache_key = self._get_key(grammar_hash)
        memcache.get(cache_key, namespace="rply")

    def dump(self, grammar_hash, data):
        cache_key = self._get_key(grammar_hash)
        memcache.set(cache_key, data, namespace="rply")

cache = AppEngineCache('myid')
ParserGenerator(["VALUE"], cache=cache)
sn6uv commented 9 years ago

This conflicted with my other changes (in docs), so I've rebased on master.

I think this is ready now

sn6uv commented 9 years ago

Any word on this PR?

sn6uv commented 9 years ago

@alex any updates on this?