Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bahn-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
bahn-api
Commits
30070c85
Commit
30070c85
authored
6 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Another attempt at fixing cache
parent
6cf27c90
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
client.go
+19
-35
19 additions, 35 deletions
client.go
with
19 additions
and
35 deletions
client.go
+
19
−
35
View file @
30070c85
...
@@ -22,9 +22,9 @@ type ApiClient struct {
...
@@ -22,9 +22,9 @@ type ApiClient struct {
const
cacheTimestamp
=
"2006-01-02T15:04"
const
cacheTimestamp
=
"2006-01-02T15:04"
func
(
c
*
ApiClient
)
loadWithCache
(
key
string
,
result
interface
{},
load
func
(
*
interface
{}
)
error
)
error
{
func
(
c
*
ApiClient
)
loadWithCache
(
key
string
,
result
interface
{},
load
func
(
)
(
interface
{}
,
error
)
)
error
{
for
_
,
cache
:=
range
c
.
Caches
{
for
_
,
cache
:=
range
c
.
Caches
{
if
err
:=
cache
.
Get
(
key
,
&
result
);
err
==
nil
{
if
err
:=
cache
.
Get
(
key
,
result
);
err
==
nil
{
for
_
,
targetCache
:=
range
c
.
Caches
{
for
_
,
targetCache
:=
range
c
.
Caches
{
if
targetCache
==
cache
{
if
targetCache
==
cache
{
break
break
...
@@ -35,7 +35,7 @@ func (c *ApiClient) loadWithCache(key string, result interface{}, load func(*int
...
@@ -35,7 +35,7 @@ func (c *ApiClient) loadWithCache(key string, result interface{}, load func(*int
}
}
}
}
var
err
error
var
err
error
if
err
=
load
(
&
result
);
err
==
nil
{
if
result
,
err
=
load
();
err
==
nil
{
for
_
,
cache
:=
range
c
.
Caches
{
for
_
,
cache
:=
range
c
.
Caches
{
_
=
cache
.
Set
(
key
,
result
)
_
=
cache
.
Set
(
key
,
result
)
}
}
...
@@ -46,10 +46,8 @@ func (c *ApiClient) loadWithCache(key string, result interface{}, load func(*int
...
@@ -46,10 +46,8 @@ func (c *ApiClient) loadWithCache(key string, result interface{}, load func(*int
func
(
c
*
ApiClient
)
Station
(
evaId
int64
)
([]
Station
,
error
)
{
func
(
c
*
ApiClient
)
Station
(
evaId
int64
)
([]
Station
,
error
)
{
key
:=
fmt
.
Sprintf
(
"realtime_recent %d"
,
evaId
)
key
:=
fmt
.
Sprintf
(
"realtime_recent %d"
,
evaId
)
var
result
[]
Station
var
result
[]
Station
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadStation
(
evaId
)
*
target
,
err
=
c
.
loadStation
(
evaId
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -81,10 +79,8 @@ func (c *ApiClient) Timetable(evaId int64, date time.Time) (Timetable, error) {
...
@@ -81,10 +79,8 @@ func (c *ApiClient) Timetable(evaId int64, date time.Time) (Timetable, error) {
key
:=
fmt
.
Sprintf
(
"timetable %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
key
:=
fmt
.
Sprintf
(
"timetable %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
var
result
Timetable
var
result
Timetable
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadTimetable
(
evaId
,
date
)
*
target
,
err
=
c
.
loadTimetable
(
evaId
,
date
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -117,10 +113,8 @@ func (c *ApiClient) RealtimeAll(evaId int64, date time.Time) (Timetable, error)
...
@@ -117,10 +113,8 @@ func (c *ApiClient) RealtimeAll(evaId int64, date time.Time) (Timetable, error)
key
:=
fmt
.
Sprintf
(
"realtime_all %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
key
:=
fmt
.
Sprintf
(
"realtime_all %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
var
result
Timetable
var
result
Timetable
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadRealtimeAll
(
evaId
,
date
)
*
target
,
err
=
c
.
loadRealtimeAll
(
evaId
,
date
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -152,10 +146,8 @@ func (c *ApiClient) RealtimeRecent(evaId int64, date time.Time) (Timetable, erro
...
@@ -152,10 +146,8 @@ func (c *ApiClient) RealtimeRecent(evaId int64, date time.Time) (Timetable, erro
key
:=
fmt
.
Sprintf
(
"realtime_recent %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
key
:=
fmt
.
Sprintf
(
"realtime_recent %d %s"
,
evaId
,
date
.
Format
(
cacheTimestamp
))
var
result
Timetable
var
result
Timetable
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadRealtimeRecent
(
evaId
,
date
)
*
target
,
err
=
c
.
loadRealtimeRecent
(
evaId
,
date
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -187,10 +179,8 @@ func (c *ApiClient) WingDefinition(parent string, wing string) (WingDefinition,
...
@@ -187,10 +179,8 @@ func (c *ApiClient) WingDefinition(parent string, wing string) (WingDefinition,
key
:=
fmt
.
Sprintf
(
"wing_definition %s %s"
,
parent
,
wing
)
key
:=
fmt
.
Sprintf
(
"wing_definition %s %s"
,
parent
,
wing
)
var
result
WingDefinition
var
result
WingDefinition
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadWingDefinition
(
parent
,
wing
)
*
target
,
err
=
c
.
loadWingDefinition
(
parent
,
wing
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -222,10 +212,8 @@ func (c *ApiClient) CoachSequence(line string, date time.Time) (CoachSequence, e
...
@@ -222,10 +212,8 @@ func (c *ApiClient) CoachSequence(line string, date time.Time) (CoachSequence, e
key
:=
fmt
.
Sprintf
(
"coach_sequence %s %s"
,
line
,
date
.
Format
(
cacheTimestamp
))
key
:=
fmt
.
Sprintf
(
"coach_sequence %s %s"
,
line
,
date
.
Format
(
cacheTimestamp
))
var
result
CoachSequence
var
result
CoachSequence
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadCoachSequence
(
line
,
date
)
*
target
,
err
=
c
.
loadCoachSequence
(
line
,
date
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -257,10 +245,8 @@ func (c *ApiClient) Suggestions(line string, date time.Time) ([]Suggestion, erro
...
@@ -257,10 +245,8 @@ func (c *ApiClient) Suggestions(line string, date time.Time) ([]Suggestion, erro
key
:=
fmt
.
Sprintf
(
"suggestions %s %s"
,
line
,
date
.
Format
(
cacheTimestamp
))
key
:=
fmt
.
Sprintf
(
"suggestions %s %s"
,
line
,
date
.
Format
(
cacheTimestamp
))
var
result
[]
Suggestion
var
result
[]
Suggestion
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadSuggestions
(
line
,
date
)
*
target
,
err
=
c
.
loadSuggestions
(
line
,
date
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
@@ -313,10 +299,8 @@ func (c *ApiClient) HafasMessages(trainlink string) ([]HafasMessage, error) {
...
@@ -313,10 +299,8 @@ func (c *ApiClient) HafasMessages(trainlink string) ([]HafasMessage, error) {
key
:=
fmt
.
Sprintf
(
"hafas_messages %s"
,
trainlink
)
key
:=
fmt
.
Sprintf
(
"hafas_messages %s"
,
trainlink
)
var
result
[]
HafasMessage
var
result
[]
HafasMessage
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
(
target
*
interface
{})
error
{
err
:=
c
.
loadWithCache
(
key
,
&
result
,
func
()
(
interface
{},
error
)
{
var
err
error
return
c
.
loadHafasMessages
(
trainlink
)
*
target
,
err
=
c
.
loadHafasMessages
(
trainlink
)
return
err
})
})
return
result
,
err
return
result
,
err
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment