Global cache for various jobs using the same plugin

23 views
Skip to first unread message

Marcin Zajączkowski

unread,
Apr 11, 2016, 12:29:59 PM4/11/16
to Jenkins Developers
Hi,

In the plugin implemented as Notifier (Rundeck plugin) I would like to add global cache (one, available for every job using that plugin) to not make the same REST call for various jobs (which on a Jenkins instance hundreds of jobs increase startup time slightly).

Is there any mechanism (a place) in Jenkins which I could use to store those cached values? If not what is a preferred solution to implement cope with it?

Marcin

--
http://blog.solidsoft.info/ - Solid Soft - Working code is not enough

Marcin Zajączkowski

unread,
Apr 12, 2016, 3:56:38 AM4/12/16
to Jenkins Developers
On Monday, April 11, 2016 at 6:29:59 PM UTC+2, Marcin Zajączkowski wrote:
Hi,

In the plugin implemented as Notifier (Rundeck plugin) I would like to add global cache (one, available for every job using that plugin) to not make the same REST call for various jobs (which on a Jenkins instance hundreds of jobs increase startup time slightly).

Is there any mechanism (a place) in Jenkins which I could use to store those cached values? If not what is a preferred solution to implement cope with it?

As In fact it is only needed when jobs are parsed at the Jenkins startup (RundeckJobProjectLinker)Action is created for every build in the history, so the requirements can be simplified to make it available only on master (no need to propagate across slaves) and it can be transient (rebuilt on reset). Static ConcurrentHashMap in that class would be probably the easiest implementation, but it smells bad. Maybe there is a storage in Jenkins to keep those shared values?

Marcin

 

Robert Sandell

unread,
Apr 12, 2016, 6:16:14 AM4/12/16
to jenkin...@googlegroups.com
Just annotate any class with @Extension and Jenkins will instantiate it as a singelton and manage it's lifecycle. You can get it via ExtensionList.lookup(YourClass.class)

And for good measure annotate it with @Restricted(NoExternalUse) to hinder other plugins from using it.

/B

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/f879d1b3-b6a6-4352-ba6b-5946e76bc02d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Marcin Zajączkowski

unread,
Apr 22, 2016, 4:59:39 PM4/22/16
to jenkin...@googlegroups.com
On 2016-04-12 12:16, Robert Sandell wrote:
> Just annotate any class with @Extension and Jenkins will instantiate it as
> a singelton and manage it's lifecycle. You can get it via
> ExtensionList.lookup(YourClass.class)
>
> And for good measure annotate it with @Restricted(NoExternalUse) to hinder
> other plugins from using it.

Thanks Robert. It helped me a lot.

Btw, people looking in the future for in memory cache solutions (and
reading that post) may be interested in Guava and its cache solution:
https://github.com/google/guava/wiki/CachesExplained

Marcin


>
> /B
>
> On Tue, Apr 12, 2016 at 9:56 AM, Marcin Zajączkowski <msz...@wp.pl> wrote:
>
>> On Monday, April 11, 2016 at 6:29:59 PM UTC+2, Marcin Zajączkowski wrote:
>>>
>>> Hi,
>>>
>>> In the plugin implemented as Notifier (Rundeck plugin) I would like to
>>> add global cache (one, available for every job using that plugin) to not
>>> make the same REST call for various jobs (which on a Jenkins instance
>>> hundreds of jobs increase startup time slightly).
>>>
>>> Is there any mechanism (a place) in Jenkins which I could use to store
>>> those cached values? If not what is a preferred solution to implement cope
>>> with it?
>>>
>>
>> As In fact it is only needed when jobs are parsed at the Jenkins startup
>> (RundeckJobProjectLinker)Action is created for every build in the history,
>> so the requirements can be simplified to make it available only on master
>> (no need to propagate across slaves) and it can be transient (rebuilt on
>> reset). Static ConcurrentHashMap in that class would be probably the
>> easiest implementation, but it smells bad. Maybe there is a storage in
>> Jenkins to keep those shared values?
>>
>> Marcin
>>
>>
>>
>>>
>>> Marcin


--
http://blog.solidsoft.info/ - Working code is not enough

Reply all
Reply to author
Forward
0 new messages