function brightcove_cache_initialize in Brightcove Video Connect 7.3
Same name and namespace in other branches
- 7.4 brightcove.module \brightcove_cache_initialize()
- 7.5 brightcove.module \brightcove_cache_initialize()
Initialize Brightcove API Cache.
Parameters
null $type:
null $time:
null $location:
null $extension:
null $port:
Return value
BCMAPICache|bool
2 calls to brightcove_cache_initialize()
- brightcove_cache_get in ./
brightcove.module - Return the cached data based on the type of the caching.
- brightcove_cache_set in ./
brightcove.module - Cache Brightcove data according to the type of caching being set.
File
- ./
brightcove.module, line 1367 - Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.
Code
function brightcove_cache_initialize($type = NULL, $time = NULL, $location = NULL, $extension = NULL, $port = NULL) {
include_once brightcove_mapi_path() . '/bc-mapi-cache.php';
// Cache type.
if (!$type) {
$type = variable_get('brightcove_cache_type', 'db');
if (!in_array($type, array(
'file',
'memcached',
))) {
drupal_set_message(t('Cannot initialize Brightcove API Cache. Contact site administrators.'), 'error');
watchdog('brightcove', 'The given @type cache type is not supported by Brightcove MAPI SDK.', array(
'@type' => $type,
), WATCHDOG_ERROR);
return FALSE;
}
else {
$cache_settings = variable_get('brightcove_cache_' . $type, array());
}
}
// Cache lifetime in seconds.
if (!$time) {
$time = isset($cache_settings['cache_time']) ? $cache_settings['cache_time'] : BRIGHTCOVE_CACHE_LIFETIME;
}
// Location of the cache dir or the Memcache server.
if (!$location) {
$default_path = $type === 'file' ? BRIGHTCOVE_CACHE_FILE_PATH : BRIGHTCOVE_CACHE_MEMCACHE_PATH;
$location = isset($cache_settings['path']) ? $cache_settings['path'] : $default_path;
}
// Check that the path of the cache directory has the closing "/" character.
if ($type === 'file') {
$location = _brightcove_cache_fix_file_path($location);
}
// Extension of the cache files.
if (!$extension) {
$extension = '.';
$extension .= isset($cache_settings['ext']) ? $cache_settings['ext'] : BRIGHTCOVE_CACHE_FILE_EXT;
}
// Memcache port.
if (!$port) {
$port = isset($cache_settings['port']) ? $cache_settings['port'] : BRIGHTCOVE_CACHE_MEMCACHE_PORT;
}
try {
$bc_cache = new BCMAPICache($type, $time, $location, $extension, $port);
} catch (Exception $e) {
watchdog_exception('brightcove', $e);
return FALSE;
}
return $bc_cache;
}