| 1 | package Plack::App::AtteanX::Query::Cache; | ||
| 2 | |||
| 3 | our $AUTHORITY = 'cpan:KJETILK'; | ||
| 4 | our $VERSION = '0.002'; | ||
| 5 | |||
| 6 | use Attean; | ||
| 7 | use Attean::RDF; | ||
| 8 | use RDF::Trine; | ||
| 9 | use Moo; | ||
| 10 | use AtteanX::Endpoint; | ||
| 11 | use CHI; | ||
| 12 | use Redis; | ||
| 13 | use LWP::UserAgent::CHICaching; | ||
| 14 | use AtteanX::Model::SPARQLCache::LDF; | ||
| 15 | use AtteanX::QueryPlanner::Cache::LDF; | ||
| 16 | use AtteanX::Query::Cache; | ||
| 17 | use Try::Tiny; | ||
| 18 | |||
| 19 | extends 'Plack::App::AtteanX::Endpoint'; | ||
| 20 | with 'MooX::Log::Any'; | ||
| 21 | |||
| 22 | sub prepare_app { | ||
| 23 | my $self = shift; | ||
| 24 | my $config = $self->{config}; | ||
| 25 | my $redisserver = 'robin.kjernsmo.net:6379'; | ||
| 26 | my $sparqlurl = 'http://dbpedia.org/sparql'; | ||
| 27 | my $ldfurl = 'http://fragments.dbpedia.org/2015/en'; | ||
| 28 | my $sparqlstore = Attean->get_store('SPARQL')->new(endpoint_url => $sparqlurl); | ||
| 29 | my $ldfstore = Attean->get_store('LDF')->new(start_url => $ldfurl); | ||
| 30 | my $cache = CHI->new( | ||
| 31 | driver => 'Redis', | ||
| 32 | namespace => 'cache', | ||
| 33 | server => $redisserver, | ||
| 34 | debug => 0 | ||
| 35 | ); | ||
| 36 | my $redissub = Redis->new(server => $redisserver, name => 'subscriber'); | ||
| 37 | |||
| 38 | RDF::Trine::default_useragent(LWP::UserAgent::CHICaching->new(cache => $cache)); | ||
| 39 | |||
| 40 | my $model = AtteanX::Model::SPARQLCache::LDF->new( store => $sparqlstore, | ||
| 41 | ldf_store => $ldfstore, | ||
| 42 | cache => $cache, | ||
| 43 | publisher => $redissub); | ||
| 44 | $self->{config} = {}; | ||
| 45 | |||
| 46 | # try { | ||
| 47 | $self->{endpoint} = AtteanX::Query::Cache->new(model => $model, | ||
| 48 | planner => AtteanX::QueryPlanner::Cache->new, | ||
| 49 | conf => $self->{config}, | ||
| 50 | graph => iri('http://example.org/graph')); | ||
| 51 | # }; | ||
| 52 | # if ($@) { | ||
| 53 | # $self->log->error($@); | ||
| 54 | # } | ||
| 55 | } | ||
| 56 | |||
| 57 | 1; |