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

Add configurable cache deltas #642

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add configurable cache deltas #642

wants to merge 4 commits into from

Conversation

eskerda
Copy link
Owner

@eskerda eskerda commented Nov 21, 2023

Current caching strategies are undefined. We use caching for both storing authentication nonces and for systems that use a single feed for more than one network within the system.

This PR tries to add a configurable layer for caching that is completely user defined. Any configuration that we would explicitly provide and hardcode would not be suitable for all uses of this library. In the cases where it makes sense to hardcode it (auth), it is providen by a new cache_for argument to scraper.request.

The configuration layer is provided as a list of hashes that are defined using regex syntax. Rules follow this pattern: module::tag::method::url. This is a sample configuration

[
     # hourly for list of stations
     {'db::.*::get_station_information': 60 * 60},
     # daily for types of vehicles
     {'db::.*::get_vehicle_types': 60 * 60 * 24},
     # daily for gbfs root url
     {'db::.*::get_feeds': 60 * 60 * 24},
     # anything else does not get cached
     {'db::.*': 0},

     # hourly for list of stations
     {'callabike::.*::get_station_information': 60 * 60},
     # daily for types of vehicles
     {'callabike::.*::get_vehicle_types': 60 * 60 * 24},
     # daily for gbfs root url
     {'callabike::.*::get_feeds': 60 * 60 * 24},
     # cache anything else, since all instances use a single feed
     {'callabike::.*': 60},

     # Cache all nextbike calls, since system uses single feeds
     {'.*nextbike-live.xml': 60},

     # Cache all publibike calls, since system uses single feeds
     {'publibike::.*': 60},
]

I have yet not decided if I want to include a set of defaults or not. Probably yes

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

Successfully merging this pull request may close these issues.

1 participant