Overview

Packages

  • LegiScan
    • API
    • Cache
    • Common
    • Exceptions
    • Utility
  • PHP

Classes

  • LegiScan_Cache_File
  • LegiScan_Cache_Memory
  • Overview
  • Package
  • Class

Class LegiScan_Cache_File

LegiScan API File Cache Class

Basic file caching with expirations to cache API responses and build permanent local bill text / document storage. To generate the path fragment under each respective cache directories use LegiScan_Pull::getCacheFilename() or LegiScan_Process::getCacheFilename().

API cache

As a dynamic API cache this stores pull API requests and search results in a local directory structure if there are no errors and subsequent calls to the same API hook will replay.

Directory structure where {api_dir} is from LegiScan::getConfig('api_dir')

  • {api_dir}/amendment/AMENDMENT_ID.json
  • {api_dir}/bill/BILL_ID.json
  • {api_dir}/masterlist/SESSION_ID.json
  • {api_dir}/people/PEOPLE_ID.json
  • {api_dir}/rollcall/ROLL_CALL_ID.json
  • {api_dir}/search/SEARCH_GUID.json
  • {api_dir}/sessionlist/STATE.json
  • {api_dir}/supplement/SUPPLEMENT_ID.json
  • {api_dir}/text/TEXT_ID.json

Document cache

As a static document cache this is the basis for local storage of related documents (bill texts, amendments, supplements) as a well structured archive that can be easily accessed by humans and automation.

Directory structure TYPE/STATE/SESSION_ID/BILL_NUMBER/ID/MIME_EXT where {doc_dir} is from LegiScan::getConfig('doc_dir')

  • {doc_dir}/amendment/tx/1478/hb1/3928402/pdf
  • {doc_dir}/supplement/md/1412/sb493/56768/pdf
  • {doc_dir}/text/ca/1400/sb1/1439083/html
Package: LegiScan\Cache
Copyright: 2010-2020 LegiScan LLC
License: https://opensource.org/licenses/BSD-2-Clause
Author: LegiScan API Team api@legiscan.com
See: LegiScan_Pull::getCacheFilename
See: LegiScan_Process::getCacheFilename
Link: https://api.legiscan.com/dl/
Located at LegiScan.php
Methods summary
public
# __construct( string $type, integer $lifetime = self::LIFETIME )

Class constructor

Class constructor

Parameters

$type
Type of cache {api, doc}
$lifetime
Time in seconds for api cache lifetime

Throws

APIAccessException
public mixed
# get( string $file, integer $lifetime = null )

Get an entry from the cache, if operating as API cache also enfore expiration lifetime, otherwise treat as a permanent document archive

Get an entry from the cache, if operating as API cache also enfore expiration lifetime, otherwise treat as a permanent document archive

Parameters

$file

$cache_file File location to retrieve, this may include additional directories under cache_dir

$lifetime
Max age in seconds that a cached file is valid

Returns

mixed
The contents of the cache location or FALSE for missing/stale
public boolean
# set( string $file, string $data )

Put an entry into the cache, creating any nested directories as required

Put an entry into the cache, creating any nested directories as required

Parameters

$file
File location to store, this may include additional directories under cache_dir
$data
Data to store in cache location

Returns

boolean
Indicating the success/failure of storing the data

Throws

APIAccessException
public boolean
# clean( $verbose = false )

Clean the API cache of stale entries

Clean the API cache of stale entries

Returns

boolean
Indicating the success/failure of the cleanup

Throws

APIAccessException
Constants summary
integer TYPE_API

Type - API (expiration)

Type - API (expiration)

# 1
integer TYPE_DOC

Type - Document (permanent)

Type - Document (permanent)

# 2
integer LIFETIME

Default lifetime of API cache objects in seconds (60 minutes)

Default lifetime of API cache objects in seconds (60 minutes)

# 3600
Properties summary
private $lifetime

Lifetime of API cache objects

Lifetime of API cache objects

#
private $cache_type

Type of cache

Type of cache

#
private $cache_dir

Base directory for cached files

Base directory for cached files

#
LegiScan API Client API documentation generated by ApiGen