Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache TTL clarification #112

Closed
creimers opened this issue Jan 30, 2018 · 5 comments
Closed

Cache TTL clarification #112

creimers opened this issue Jan 30, 2018 · 5 comments
Labels

Comments

@creimers
Copy link

Good evening,

I have a question regarding the cache and its time to live.

Let's say I want to turn some site into an API and want the results of the very first request to be cached for one hour. How would I specify that in the settings? Is such a setup even possible?

I tried setting ttl: 60 * 60, assuming that that would do the trick. But to me it seems it doesn't...

Could you please clarify?

Thanks in advance.

@howie6879
Copy link
Contributor

Hi @creimers

How do you set ttl?

cache = {
        'cache_class': MemoryCache,
        'cache_config': {},
        'serializer': StrSerializer,
        'ttl': 3
    }

@creimers
Copy link
Author

Hey @howie6879 ,

my settings look like this. Pretty much how they came out of the generated project.

class MySettings(Settings):

    cache = {
        'cache_class': MemoryCache,
        'cache_config': {},
        'serializer': None,
        'ttl': 60 * 60
    }
    storage = {
        "PATH": os.path.dirname(os.path.abspath(__file__)),
        "DB_URL": None
    }
    web = {
        "with_ajax": False,
        "request_config": {},
        "headers": None
    }

@howie6879
Copy link
Contributor

Hi @creimers ,
There is no problem with your settings.
I tried setting ttl: 2 * 3, the result is what I want:

2018/02/01 08:27:51 [Cache   ] OK Set</one/> 
2018/02/01 08:27:51 [Received] OK http://127.0.0.1:5000/one/ 6216 200 42.69ms 
2018/02/01 08:27:54 [Cache   ] OK Get</one/> 
2018/02/01 08:27:54 [Received] OK http://127.0.0.1:5000/one/ 6216 200 0.20ms 
2018/02/01 08:27:58 [Storage ] OK Get<http://wufazhuce.com/> 
2018/02/01 08:27:58 [Parsed  ] OK Item<Indexone[1]> 
2018/02/01 08:27:58 [Parsed  ] OK Item<Indexarticle[4]> 
2018/02/01 08:27:58 [Parsed  ] OK Item<Indexquestion[4]> 
2018/02/01 08:27:58 [Cache   ] OK Set</one/> 

@creimers
Copy link
Author

creimers commented Feb 1, 2018

Hi. Thanks.

I can confirm that I can reproduce a similar behavior.

However, it is also the case that the results I get to see after the cache has died and new results are fetched are the same as the cached ones. Even if I know for sure that the data source has changed.

Once I delete the .html folder, I do get updated results. Anything I'm missing here?

@howie6879
Copy link
Contributor

howie6879 commented Feb 2, 2018

Hi, @creimers

Sorry for the inconvenience, we allow users to set expiration time in storage, it looks like a bit of a problem now.

We will fix this issue quickly.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants